<p>What field type is blog_featured_image? Just an image asset?
Does it work with</p>

<p><code>&lt;img src="{{ asset.getUrl() }}" alt="{{asset.title}}" /&gt;</code> ?</p>

CC BY-SA 3.0
2017-01-20T04:51:43.967Z
The blog_featured_image is just an image asset.
FuzzyJelly
CC BY-SA 3.0
2017-01-20T04:57:18.520Z
I attempted to use it within the ElementCriteriaModel doc (https://craftcms.com/docs/templating/craft.assets) but I couldn't get it to work.

The base path and base url in the Settings > Assets are produced exactly (if I use {siteUrl} it outputs {siteUrl}assets/images rather than "http://example.com/assets/images"

Unfortunately, using the same code you suggested didn't do it either. I'm missing something obvious, I'm sure, but I can't find it.
FuzzyJelly
CC BY-SA 3.0
2017-01-20T08:22:50.693Z
How does your general.php look like? Maybe a typo there?
Andreas
CC BY-SA 3.0
2017-01-20T15:27:24.310Z
There are no additional settings in general.php yet, I tried adding some siteUrl updates and have since removed them, so now it's empty. I realize now that it's the siteUrl that I added into the asset settings that's being passed through, so I think my question is answered and I need to research dynamic asset settings paths. Thank you!
FuzzyJelly
CC BY-SA 3.0
2017-01-19T15:30:53.410Z
2017-01-19T15:30:53.410Z
Andreas
<p>You need the <code>.getUrl();</code> I also suggest that you have a look at the <a href="https://github.com/aelvan/Imager-Craft" rel="nofollow noreferrer">Imager plugin</a> for a more flexible use of images in your site.</p>

CC BY-SA 3.0
2017-01-20T05:05:03.777Z
asset.getUrl() DOES get the url, but it omits the main base url (in this instance "localhost/public/" and leaves in {siteUrl} in the finished code: ( I.E. {{asset.getUrl()}} == "{siteUrl}assets/filename.jpg" )
FuzzyJelly
CC BY-SA 3.0
2017-01-19T18:02:59.137Z
2017-01-19T18:02:59.137Z
Jan_dh
<p>I'm very new at Craft templating, and I can't seem to get an asset to link correctly in the browser.</p>

<pre><code>{% block content %}
    &lt;article&gt;
        &lt;h1&gt;{{ entry.title }}&lt;/h1&gt;
        {{ siteUrl }}
        &lt;p&gt;Posted on {{ entry.postDate.format('F d, Y') }}&lt;/p&gt;
        {{ entry.blog_body }}
        {% for asset in entry.blog_featured_image %}
            &lt;img src="{{asset.url}}" alt="{{asset.title}}" /&gt;
        {% endfor %}
    &lt;/article&gt;
{% endblock %}
</code></pre>

<p>Becomes this:</p>

<pre><code>&lt;article&gt;
  &lt;h1&gt;New Blog 1&lt;/h1&gt;
  http://localhost/craftcms/public/
  &lt;p&gt;Posted on January 15, 2017&lt;/p&gt;
  &lt;p&gt;"Body Text"&lt;/p&gt;
  &lt;img src="{{ siteUrl }}assets/images/image.png" alt="title"&gt;
&lt;/article&gt;
</code></pre>

<p>when output to a browser.</p>

<p>{{ siteUrl }} will display the path just fine, but when I'm using {{asset.url}} and it gets changed to {{siteUrl}} it doesn't create the path, it just stays at siteUrl. This is really confusing me.</p>

<p>Why doesn't {{ siteUrl }} return the base path when it's used in the asset.url?</p>

CC BY-SA 3.0
2017-01-19T17:16:45.500Z
In your asset settings for that source do you have something like `{{ siteUrl }}/images` in the input field? If so, try changing it to `{siteUrl}` and see if that helps.
Alec Ritson
<assets><siteurl>
Localhost: Why does {{ asset.url }} return {{siteUrl}}/path in the browser?
# Localhost: Why does {{ asset.url }} return {{siteUrl}}/path in the browser?

(Asked by: username_0 on 2017-01-15)

I'm very new at Craft templating, and I can't seem to get an asset to link correctly in the browser.
{% block content %}
    
        {{ entry.title }}
        {{ siteUrl }}
        Posted on {{ entry.postDate.format('F d, Y') }}
        {{ entry.blog_body }}
        {% for asset in entry.blog_featured_image %}
            
        {% endfor %}
    
{% endblock %}

Becomes this:

  New Blog 1
  http://localhost/craftcms/public/
  Posted on January 15, 2017
  "Body Text"
  


when output to a browser.
{{ siteUrl }} will display the path just fine, but when I'm using {{asset.url}} and it gets changed to {{siteUrl}} it doesn't create the path, it just stays at siteUrl. This is really confusing me.
Why doesn't {{ siteUrl }} return the base path when it's used in the asset.url?

**Tags:** assets, siteurl

> **Comments:**
> **username_1**: In your asset settings for that source do you have something like `{{ siteUrl }}/images` in the input field? If so, try changing it to `{siteUrl}` and see if that helps.  

---

## 2 answers

### Answer by username_2 on 2017-01-19. Score: 2 | Accepted answer

What field type is blog\_featured\_image? Just an image asset?
Does it work with

`![{{asset.title}}]({{ asset.getUrl() }})` ?

> **Comments:**
> **username_0**: The blog_featured_image is just an image asset.  
> **username_0**: I attempted to use it within the ElementCriteriaModel doc (https://craftcms.com/docs/templating/craft.assets) but I couldn't get it to work.  The base path and base url in the Settings > Assets are produced exactly (if I use {siteUrl} it outputs {siteUrl}assets/images rather than "http://example.com/assets/images"  Unfortunately, using the same code you suggested didn't do it either. I'm missing something obvious, I'm sure, but I can't find it.  
> **username_2**: How does your general.php look like? Maybe a typo there?  
> **username_0**: There are no additional settings in general.php yet, I tried adding some siteUrl updates and have since removed them, so now it's empty. I realize now that it's the siteUrl that I added into the asset settings that's being passed through, so I think my question is answered and I need to research dynamic asset settings paths. Thank you!  

---

### Answer by username_3 on 2017-01-19. Score: 1

You need the `.getUrl();` I also suggest that you have a look at the [Imager plugin](https://github.com/aelvan/Imager-Craft) for a more flexible use of images in your site.

> **Comments:**
> **username_0**: asset.getUrl() DOES get the url, but it omits the main base url (in this instance "localhost/public/" and leaves in {siteUrl} in the finished code: ( I.E. {{asset.getUrl()}} == "{siteUrl}assets/filename.jpg" )  

---

