<p>I think your problem is here:</p>

<pre><code>{% set assets = artwork.pictures.first() %}
{% if assets | length %}
  {% for asset in assets %}
</code></pre>

<p>This sets <code>assets</code> to the first <code>artwork.pictures</code>, not to a list of assets, and then you try to loop over that single asset.</p>

<p>If you want a <code>figure</code> for every <code>pictures</code> of every <code>selectedArtwork</code> of your entry, try this:</p>

<pre><code>{% set artworkPicture = { width: 475 } %}
{% set artworkPictureRetina = { width: 930 } %}

{% for artwork in entry.selectedArtwork %}
  {% for asset in artwork.pictures %}
    &lt;figure&gt;
      &lt;img data-interchange="[{{ asset.getUrl(artworkPicture) }}, (default)], [{{ asset.getUrl(artworkPictureRetina) }}, (retina)]" width="{{ asset.getWidth(artworkPicture) }}" height="{{ asset.getHeight(artworkPicture) }}"&gt;
      &lt;noscript&gt;
        &lt;img src="{{ asset.getUrl(artworkPicture) }}" width="{{ asset.getWidth(artworkPicture) }}" height="{{ asset.getHeight(artworkPicture) }}"&gt;
      &lt;/noscript&gt;
    &lt;/figure&gt;
  {% endfor %}
{% endfor %}
</code></pre>

<ul>
<li>set <code>artworkPicture</code> and <code>artworkPictureRetina</code> once, outside your loop.</li>
<li>no need to use <code>{% if ...|length %}</code>. If the length is 0, the for loop will run 0 times.</li>
</ul>

<p>If you want a <code>figure</code> for the first <code>picture</code> of every <code>selectedArtwork</code>, try this:</p>

<pre><code>{% set artworkPicture = { width: 475 } %}
{% set artworkPictureRetina = { width: 930 } %}

{% for artwork in entry.selectedArtwork %}
  {% set asset = artwork.pictures.first %}
  {% if asset %}
    &lt;figure&gt;
      &lt;img data-interchange="[{{ asset.getUrl(artworkPicture) }}, (default)], [{{ asset.getUrl(artworkPictureRetina) }}, (retina)]" width="{{ asset.getWidth(artworkPicture) }}" height="{{ asset.getHeight(artworkPicture) }}"&gt;
      &lt;noscript&gt;
        &lt;img src="{{ asset.getUrl(artworkPicture) }}" width="{{ asset.getWidth(artworkPicture) }}" height="{{ asset.getHeight(artworkPicture) }}"&gt;
      &lt;/noscript&gt;
    &lt;/figure&gt;
  {% endif %}
{% endfor %}
</code></pre>

<p>If you want a <code>figure</code> for the first <code>picture</code> of the first <code>selectedArtwork</code>, try this:</p>

<pre><code>{% set artworkPicture = { width: 475 } %}
{% set artworkPictureRetina = { width: 930 } %}

{% set artwork = entry.selectedArtwork.first %}
{% if artwork %}
  {% set asset = artwork.pictures.first %}
  {% if asset %}
    &lt;figure&gt;
      &lt;img data-interchange="[{{ asset.getUrl(artworkPicture) }}, (default)], [{{ asset.getUrl(artworkPictureRetina) }}, (retina)]" width="{{ asset.getWidth(artworkPicture) }}" height="{{ asset.getHeight(artworkPicture) }}"&gt;
      &lt;noscript&gt;
        &lt;img src="{{ asset.getUrl(artworkPicture) }}" width="{{ asset.getWidth(artworkPicture) }}" height="{{ asset.getHeight(artworkPicture) }}"&gt;
      &lt;/noscript&gt;
    &lt;/figure&gt;
  {% endif %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2014-07-19T17:29:45.537Z
Thanks for your solution but I'm sorry, my question was not precise enough: I was trying to display only the first 'artwork' entry of the 'entry.selectedArtwork' loop.
Romain P.
CC BY-SA 3.0
2014-07-19T17:58:54.517Z
Added that solution as well.
Marion Newlevant
CC BY-SA 3.0
2014-07-19T18:09:49.513Z
Thanks, this solves the template error but strangely it now outputs two pictures instead of only one... Any idea?
Romain P.
CC BY-SA 3.0
2014-07-19T18:42:38.393Z
2 entries in selectedArtwork?
Marion Newlevant
CC BY-SA 3.0
2014-07-19T21:19:18.913Z
Yes, in selectedArtwork.
Romain P.
CC BY-SA 3.0
2014-07-19T21:37:41.843Z
So what you want is the first `pictures` of the first `selectedArtwork`?
Marion Newlevant
CC BY-SA 3.0
2014-07-19T21:43:02.133Z
Yes, absolutely! Sorry for not being specific enough. Thanks for your help!
Romain P.
CC BY-SA 3.0
2014-07-19T22:18:35.513Z
Ok, I finally found how to:

{% for artwork in entry.selectedArtwork.limit(1).find() %}
{% set asset = artwork.pictures.first %}

So I added .limit(1).find() to output only one entry of the loop (in this case, the first), and then select only the first asset.

Thanks for your help :-)
Romain P.
CC BY-SA 3.0
2014-07-19T17:22:28.343Z
2014-07-19T22:20:46.287Z
2014-07-19T22:20:46.287Z
Marion Newlevant
<p>I'm a beginner and don't understand this error, and how to correct it:</p>

<p><strong>Template error</strong><br>
Impossible to invoke a method ("getUrl") on a string variable ("60")</p>

<p>I'm trying to display only the first entry of one loop. In my case,<br>
'<em>selectedArtwork</em>' has an <em>Entries</em> type and '<em>pictures</em>' an <em>Assets</em> type.</p>

<p>Here is my code:</p>

<pre><code>{% if entry.selectedArtwork | length %}
    {% for artwork in entry.selectedArtwork %}

        {% set assets = artwork.pictures.first() %}
        {% if assets | length %}
            {% for asset in assets %}

                {% set artworkPicture = { width: 475 } %}
                {% set artworkPictureRetina = { width: 930 } %}

                &lt;figure&gt;
                    &lt;img data-interchange="[{{ asset.getUrl(artworkPicture) }}, (default)], [{{ asset.getUrl(artworkPictureRetina) }}, (retina)]" width="{{ asset.getWidth(artworkPicture) }}" height="{{ asset.getHeight(artworkPicture) }}"&gt;

                    &lt;noscript&gt;
                        &lt;img src="{{ asset.getUrl(artworkPicture) }}" width="{{ asset.getWidth(artworkPicture) }}" height="{{ asset.getHeight(artworkPicture) }}"&gt;
                    &lt;/noscript&gt;
                &lt;/figure&gt;
            {% endfor %}
        {% endif %}
    {% endfor %}
{% endif %}
</code></pre>

<p>And the part of code highlighted in Craft's debug mode are:</p>

<pre><code>&lt;img data-interchange="[{{ asset.getUrl(artworkPicture) }}, (default)], [{{ asset.getUrl(artworkPictureRetina) }}, (retina)]" width="{{ asset.getWidth(artworkPicture) }}" height="{{ asset.getHeight(artworkPicture) }}"&gt;

&lt;noscript&gt;
    &lt;img src="{{ asset.getUrl(artworkPicture) }}" width="{{ asset.getWidth(artworkPicture) }}" height="{{ asset.getHeight(artworkPicture) }}"&gt;
&lt;/noscript&gt;
</code></pre>

<p>This code is working well as an entry template of another page of my website to display all entries, but not here for my homepage to only display the first entry.</p>

CC BY-SA 3.0
2014-07-19T17:10:00.113Z
Can you clarify what type of fields are 'selectedArtwork' and 'pictures'?  A Matrix and Assets field, respectively?
Brad Bell
CC BY-SA 3.0
2014-07-19T17:19:14.437Z
'selectedArtwork' = Entries and 'pictures' = Assets
Romain P.
<assets><entry-type>
Impossible to invoke a method ("getUrl") on a string variable ("60")
# Impossible to invoke a method ("getUrl") on a string variable ("60")

(Asked by: username_0 on 2014-07-19)

I'm a beginner and don't understand this error, and how to correct it:
Template error
Impossible to invoke a method ("getUrl") on a string variable ("60")
I'm trying to display only the first entry of one loop. In my case,
'selectedArtwork' has an Entries type and 'pictures' an Assets type.
Here is my code:
{% if entry.selectedArtwork | length %}
    {% for artwork in entry.selectedArtwork %}

        {% set assets = artwork.pictures.first() %}
        {% if assets | length %}
            {% for asset in assets %}

                {% set artworkPicture = { width: 475 } %}
                {% set artworkPictureRetina = { width: 930 } %}

                
                    

                    
                        
                    
                
            {% endfor %}
        {% endif %}
    {% endfor %}
{% endif %}

And the part of code highlighted in Craft's debug mode are:



    


This code is working well as an entry template of another page of my website to display all entries, but not here for my homepage to only display the first entry.

**Tags:** assets, entry-type
> **Comments:**
> **username_1**: Can you clarify what type of fields are 'selectedArtwork' and 'pictures'?  A Matrix and Assets field, respectively?  
> **username_0**: 'selectedArtwork' = Entries and 'pictures' = Assets  

---

## 1 answers

### Answer by username_2 on 2014-07-19. Score: 2 | Accepted answer

I think your problem is here:
{% set assets = artwork.pictures.first() %}
{% if assets | length %}
  {% for asset in assets %}

This sets assets to the first artwork.pictures, not to a list of assets, and then you try to loop over that single asset.
If you want a figure for every pictures of every selectedArtwork of your entry, try this:
{% set artworkPicture = { width: 475 } %}
{% set artworkPictureRetina = { width: 930 } %}

{% for artwork in entry.selectedArtwork %}
  {% for asset in artwork.pictures %}
    
      
      
        
      
    
  {% endfor %}
{% endfor %}


set artworkPicture and artworkPictureRetina once, outside your loop.
no need to use {% if ...|length %}. If the length is 0, the for loop will run 0 times.

If you want a figure for the first picture of every selectedArtwork, try this:
{% set artworkPicture = { width: 475 } %}
{% set artworkPictureRetina = { width: 930 } %}

{% for artwork in entry.selectedArtwork %}
  {% set asset = artwork.pictures.first %}
  {% if asset %}
    
      
      
        
      
    
  {% endif %}
{% endfor %}

If you want a figure for the first picture of the first selectedArtwork, try this:
{% set artworkPicture = { width: 475 } %}
{% set artworkPictureRetina = { width: 930 } %}

{% set artwork = entry.selectedArtwork.first %}
{% if artwork %}
  {% set asset = artwork.pictures.first %}
  {% if asset %}
    
      
      
        
      
    
  {% endif %}
{% endif %}

> **Comments:**
> **username_0**: Thanks for your solution but I'm sorry, my question was not precise enough: I was trying to display only the first 'artwork' entry of the 'entry.selectedArtwork' loop.  
> **username_2**: Added that solution as well.  
> **username_0**: Thanks, this solves the template error but strangely it now outputs two pictures instead of only one... Any idea?  
> **username_2**: 2 entries in selectedArtwork?  
> **username_0**: Yes, in selectedArtwork.  
> **username_2**: So what you want is the first `pictures` of the first `selectedArtwork`?  
> **username_0**: Yes, absolutely! Sorry for not being specific enough. Thanks for your help!  
> **username_0**: Ok, I finally found how to:  {% for artwork in entry.selectedArtwork.limit(1).find() %} {% set asset = artwork.pictures.first %}  So I added .limit(1).find() to output only one entry of the loop (in this case, the first), and then select only the first asset.  Thanks for your help :-)  

---

