<p>I bet this trips up a lot of people at first, but your asset field will return a <strong>ElementCriteriaModel</strong>, not your image.</p>

<p>To get to image, you need to fetch it. If your field has only one image, you will do something like this:</p>

<pre><code>{# Fetches the first image #}
{% set image = entry.featureImage.first() %}
{# It's good to check if you actually have an image before trying to get the url #}
{% if image %}
    {{ image.url }}
    {# Or alternatively #}
    {{ image.getUrl() }}
    {# If you want to get a specific transform: #}
    {{ image.getUrl('transformHandle') }}
{% endif %}
</code></pre>

<p><a href="http://buildwithcraft.com/docs/assets-fields#examples">The Assets fields documentation</a> got some good examples on the different use cases.</p>

CC BY-SA 3.0
2014-09-30T21:02:35.340Z
Thank you! I was missing .first(). Although I don't understand why I need to specify to get the first in the array, when the single image is the only one uploaded, it works with that added. Good tip with the checking if it exists too.
Ryan Maskell
CC BY-SA 3.0
2014-09-30T21:34:09.613Z
As Fred said, it can be confusing... It's important to specify the `first` because technically your assets field **can hold more than one asset**. Even if you've only uploaded a single asset (or even set the "maximum" allowed assets to 1), your assets field will still hold its data in an array-like format.
Lindsey D
CC BY-SA 3.0
2014-09-30T22:33:38.690Z
I've found it helpful to make sure all my relation field handles are plural, even if I only intend on there being one element. It's a lot easier to remember to add the .first if you've already got {{ entry.featureImages }}.
Mike Pepper
CC BY-SA 3.0
2014-09-30T18:55:23.333Z
2014-09-30T18:55:23.333Z
Fred Carlsen
<p>This seems like it should be really simple. I set the field for an image asset, linked it to the entry type I want it associated to, and then uploaded the image in the cms to the folder I specified.</p>

<p>So now, when I call <code>{{ entry.featureImage }}</code> it should return the object of that image. I want its URL, because I want to place it in a special image tag. <code>&lt;img class="img-responsive" src="{{ entry.featureImage }}"&gt;</code> Now I know this returns an error that says "Object could not be converted to string". Because I need to modify it to get the string of the URL. How can I do this? I feel like I've tried everything and scoured the docs and internet. I cant just attach a <code>.getURL()</code> or <code>.url</code> like would make a whole ton of sense. I've even set entry.featureImage as a variable and then called image.url on it. Or <code>.getImg('featureImage')</code> maybe? But it needs the class of img-responsive.</p>

<p>This needs to be possible so that the CMS can allow for images to be specified and uploaded for specific spots in the website.</p>

<assets><url><image>
Fetch Image URL from entry CMS
# Fetch Image URL from entry CMS

(Asked by: username_0 on 2014-09-30)

This seems like it should be really simple. I set the field for an image asset, linked it to the entry type I want it associated to, and then uploaded the image in the cms to the folder I specified.

So now, when I call `{{ entry.featureImage }}` it should return the object of that image. I want its URL, because I want to place it in a special image tag. `![]({{ entry.featureImage }})` Now I know this returns an error that says "Object could not be converted to string". Because I need to modify it to get the string of the URL. How can I do this? I feel like I've tried everything and scoured the docs and internet. I cant just attach a `.getURL()` or `.url` like would make a whole ton of sense. I've even set entry.featureImage as a variable and then called image.url on it. Or `.getImg('featureImage')` maybe? But it needs the class of img-responsive.

This needs to be possible so that the CMS can allow for images to be specified and uploaded for specific spots in the website.

**Tags:** assets, url, image


---

## 1 answers

### Answer by username_1 on 2014-09-30. Score: 16 | Accepted answer

I bet this trips up a lot of people at first, but your asset field will return a ElementCriteriaModel, not your image.
To get to image, you need to fetch it. If your field has only one image, you will do something like this:
{# Fetches the first image #}
{% set image = entry.featureImage.first() %}
{# It's good to check if you actually have an image before trying to get the url #}
{% if image %}
    {{ image.url }}
    {# Or alternatively #}
    {{ image.getUrl() }}
    {# If you want to get a specific transform: #}
    {{ image.getUrl('transformHandle') }}
{% endif %}

The Assets fields documentation got some good examples on the different use cases.

> **Comments:**
> **username_0**: Thank you! I was missing .first(). Although I don't understand why I need to specify to get the first in the array, when the single image is the only one uploaded, it works with that added. Good tip with the checking if it exists too.  
> **username_2**: As Fred said, it can be confusing... It's important to specify the `first` because technically your assets field **can hold more than one asset**. Even if you've only uploaded a single asset (or even set the "maximum" allowed assets to 1), your assets field will still hold its data in an array-like format.  
> **username_3**: I've found it helpful to make sure all my relation field handles are plural, even if I only intend on there being one element. It's a lot easier to remember to add the .first if you've already got {{ entry.featureImages }}.  

---

