<p>Yes, this is actually the intended behaviour, and one that changed when going from Craft 2 to Craft 3. You can read more about it in the <a href="https://docs.craftcms.com/v3/changes-in-craft-3.html#element-queries" rel="nofollow noreferrer">Changes in Craft 3 article in the docs</a>. <code>projectImages</code> in this case which is an Asset field (I assume), returns an ElementQuery when you access it with <code>projectPanels.projectImages</code>. The field doesn't automatically return a new model when accessed, it returns the reference to the one and same query. </p>

<p>The workaround is to either reset the parameters you need to reset, like <code>limit()</code> in this case, or use clone as described in that article.</p>

<p>Ie, either something like this:</p>

<pre><code>{% for asset in projectPanels.projectImages.limit(1).all() %}
   ...
{% endfor %}

{% for thumbs in projectPanels.projectImages.limit(null).offset(1).all() %}
   ...
{% endfor %}
</code></pre>

<p>Or,</p>

<pre><code>{% for asset in clone(projectPanels.projectImages).limit(1).all() %}
   ...
{% endfor %}

{% for thumbs in clone(projectPanels.projectImages).offset(1).all() %}
   ...
{% endfor %}
</code></pre>

<p>Have stumbled on this quite a few times myself alreadym, it's a bit confusing. Hope this helps though. :)</p>

CC BY-SA 4.0
2018-07-03T18:48:53.810Z
2018-07-03T19:09:16.970Z
2018-07-03T19:09:16.970Z
André Elvan
<p>I have an Asset field where the first image is used as a big 'feature' and then the rest are used as support further down the page.</p>

<p>When I add .limit(1) to the for loop for the 'feature' image it effects the for loop further down the page by also only showing 1 image.</p>

<p>This is my code...</p>

<pre><code>{% set entries = craft.entries.section('abstractionProjects').type('abstractionProjects').all() %}
{% for projectPanels in entries %}

    Some HTML...

    {% for asset in projectPanels.projectImages.limit(1) %}
      &lt;img src="{{ asset.url }}" alt="{{ asset.title }}"&gt;
    {% endfor %}

    Some HTML.....
    More HTML...

    {% for thumbs in projectPanels.projectImages.offset(1) %}
      &lt;div&gt;
          &lt;img src="{{ thumbs.url('projectPageThumbs') }}" alt="{{ thumbs.title }}"&gt;
          &lt;a href="{{ thumbs.url('projectPageFullSize') }}" class="gallery"&gt;&lt;/a&gt;
      &lt;/div&gt;
    {% endfor %}

    More HTML...

{% endfor %}
</code></pre>

<p>If I remove the .limit(1) from the first loop all the images are shown in both loops :/</p>

<p>Help appreciated</p>

<p>Thanks</p>

CC BY-SA 4.0
2018-07-03T16:07:20.740Z
Have you tried using `projectPanels.projectImages.first()` or `projectPanels.projectImages[0]` to access the first item.
a-am
CC BY-SA 4.0
2018-07-03T16:11:24.267Z
Thanks Aran... now I get "Impossible to access an attribute ("url") on a string variable ("3")."  when trying both .first() and [0]
Martin
CC BY-SA 4.0
2018-07-03T16:54:10.063Z
Try accessing the first asset without the for loop. `<img src="{{ projectPanels.projectImages[0].url }}" alt="{{ projectPanels.projectImages[0].title }}">`
a-am
<assets><forloop>
.limit(1) on asset field loop is effecting another loop on same page
# .limit(1) on asset field loop is effecting another loop on same page

(Asked by: username_0 on 2018-07-03)

I have an Asset field where the first image is used as a big 'feature' and then the rest are used as support further down the page.
When I add .limit(1) to the for loop for the 'feature' image it effects the for loop further down the page by also only showing 1 image.
This is my code...
{% set entries = craft.entries.section('abstractionProjects').type('abstractionProjects').all() %}
{% for projectPanels in entries %}

    Some HTML...

    {% for asset in projectPanels.projectImages.limit(1) %}
      
    {% endfor %}

    Some HTML.....
    More HTML...

    {% for thumbs in projectPanels.projectImages.offset(1) %}
      
          
          
      
    {% endfor %}

    More HTML...

{% endfor %}

If I remove the .limit(1) from the first loop all the images are shown in both loops :/
Help appreciated
Thanks

**Tags:** assets, forloop
> **Comments:**
> **username_1**: Have you tried using `projectPanels.projectImages.first()` or `projectPanels.projectImages[0]` to access the first item.  
> **username_0**: Thanks Aran... now I get "Impossible to access an attribute ("url") on a string variable ("3")."  when trying both .first() and [0]  
> **username_1**: Try accessing the first asset without the for loop. `<img src="{{ projectPanels.projectImages[0].url }}" alt="{{ projectPanels.projectImages[0].title }}">`  

---

## 1 answers

### Answer by username_2 on 2018-07-03. Score: 1 | Accepted answer

Yes, this is actually the intended behaviour, and one that changed when going from Craft 2 to Craft 3. You can read more about it in the Changes in Craft 3 article in the docs. projectImages in this case which is an Asset field (I assume), returns an ElementQuery when you access it with projectPanels.projectImages. The field doesn't automatically return a new model when accessed, it returns the reference to the one and same query. 
The workaround is to either reset the parameters you need to reset, like limit() in this case, or use clone as described in that article.
Ie, either something like this:
{% for asset in projectPanels.projectImages.limit(1).all() %}
   ...
{% endfor %}

{% for thumbs in projectPanels.projectImages.limit(null).offset(1).all() %}
   ...
{% endfor %}

Or,
{% for asset in clone(projectPanels.projectImages).limit(1).all() %}
   ...
{% endfor %}

{% for thumbs in clone(projectPanels.projectImages).offset(1).all() %}
   ...
{% endfor %}

Have stumbled on this quite a few times myself alreadym, it's a bit confusing. Hope this helps though. :)


---

