<p>This is where it goes wrong:</p>

<pre><code>{% for asset in image %}
</code></pre>

<p>Because you use <code>first()</code>, you end up with an AssetFileModel, not an array of those.
If you than loop through that AssetFileModel with a for-loop, you get all the values of that Model. They don't have a method called getUrl(), which is what causes the error.</p>

<p>So, skip the for-loop and just use:</p>

<pre><code>{% set image = entry.articleImages.first() %}
&lt;img src="{{ asset.url('worksList') }}" /&gt;
</code></pre>

<p>The <code>url()</code> method is <a href="http://buildwithcraft.com/docs/templating/assetfilemodel#url" rel="nofollow">an alias</a> for <code>getUrl()</code>.</p>

CC BY-SA 3.0
2015-01-12T13:52:19.793Z
Exactly that did the job, with one minor change: <img src="{{ image.url('worksList') }}"> Thanks
user2986
CC BY-SA 3.0
2015-01-12T13:54:04.687Z
Could you please accept the answer, then? And maybe tell me what the change was, so other users can learn from it ...
Paul
CC BY-SA 3.0
2015-01-12T13:01:02.890Z
2015-01-12T13:01:02.890Z
Paul
<p>This "standard" set-up for rendering asset transforms works as expected. </p>

<pre><code>                {% set image = entry.articleImages %}

                {% if image | length %}
                    &lt;div class="col-sm-6 col-md-6"&gt;
                        &lt;a href="{{ entry.url }}" class="work"&gt;

                            {% for asset in image %}
                                &lt;img src="{{ asset.getUrl('worksList') }}" alt="{{ asset.title }}" title="{{ asset.title }}" height="{{ asset.getHeight('worksList') }}" width="{{ asset.getWidth('worksList') }}"&gt;
                            {% endfor %}

                        &lt;/a&gt;
                    &lt;/div&gt;
                {% endif %}
</code></pre>

<p>When I only want the first image out of the assets loop I would normally add .first() to the set image loop.</p>

<pre><code>{% set image = entry.articleImages.first() %}
</code></pre>

<p>However this ends op in unclear error messages while rendering on the front-end ( Impossible to invoke a method ("getUrl") on a string variable ("111"))!
Or am I missing out on something?</p>

<assets><image-transforms><loop>
first() don't seem to work while using an image transform
# first() don't seem to work while using an image transform

(Asked by: username_0 on 2015-01-12)

This "standard" set-up for rendering asset transforms works as expected. 
                {% set image = entry.articleImages %}

                {% if image | length %}
                    
                        

                            {% for asset in image %}
                                
                            {% endfor %}

                        
                    
                {% endif %}

When I only want the first image out of the assets loop I would normally add .first() to the set image loop.
{% set image = entry.articleImages.first() %}

However this ends op in unclear error messages while rendering on the front-end ( Impossible to invoke a method ("getUrl") on a string variable ("111"))!
Or am I missing out on something?

**Tags:** assets, image-transforms, loop

---

## 1 answers

### Answer by username_1 on 2015-01-12. Score: 1

This is where it goes wrong:
{% for asset in image %}

Because you use first(), you end up with an AssetFileModel, not an array of those.
If you than loop through that AssetFileModel with a for-loop, you get all the values of that Model. They don't have a method called getUrl(), which is what causes the error.
So, skip the for-loop and just use:
{% set image = entry.articleImages.first() %}


The url() method is an alias for getUrl().

> **Comments:**
> **username_0**: Exactly that did the job, with one minor change: <img src="{{ image.url('worksList') }}"> Thanks  
> **username_1**: Could you please accept the answer, then? And maybe tell me what the change was, so other users can learn from it ...  

---

