<p>Since in Craft you will loop over an Assets field, you could use the loop.index variable: <a href="https://twig.symfony.com/doc/2.x/tags/for.html" rel="nofollow noreferrer">https://twig.symfony.com/doc/2.x/tags/for.html</a> to check for the nth iteration.</p>

CC BY-SA 4.0
2020-02-24T19:01:09.763Z
but how could I use the loop.index compared to `{if images_start:count == 1}X{if:elseif images_start:count == 2}Y{/if}`? or do I need a different direction for whole code construct?
Matthias
CC BY-SA 4.0
2020-02-25T07:44:22.833Z
The [divisible by](https://twig.symfony.com/doc/2.x/tests/divisibleby.html) test comes handy:  
`{% if loop.index is divisible by(3) %} 
This is the 3rd item 
{% endif %}`
gioppe
CC BY-SA 4.0
2020-02-24T09:24:21.907Z
2020-02-24T09:24:21.907Z
gioppe
<p>I am currently "translating" our current website, which runs on the lastest expressionengine, to craft. we use imagegrids that are arranged by css. </p>

<p>so in an entrie's pulldown field choose between several grids (named q1, q1q2, etc.) and checked via conditionals in the code to know how to style the images and to give them the right "transformations"/sizes:</p>

<pre><code>{# Imagegrid #}
    &lt;figure class="grid {imagearrange}"&gt;
        {images_start}
            {images_start:file}
                {# A (1 landscape) #}
                {if imagearrange == "q1"}
                    {if images_start:count == 1}
                        &lt;figure class="q1"&gt;
                            &lt;img src="{url:1-1-landscape}"&gt;
                        &lt;/figure&gt;
                    {/if}
                {# B (2 landscape) #}
                {if:elseif imagearrange == "q1q2"}
                    {if images_start:count == 1}
                        &lt;figure class="q1"&gt;
                            &lt;img src="{url:1-2-landscape}"&gt;
                        &lt;/figure&gt;   
                    {if:elseif images_start:count == 2}
                        &lt;figure class="q2"&gt;
                            &lt;img src="{url:1-2-landscape}"&gt;
                        &lt;/figure&gt;
                    {/if}
                {# C (1 landscape / 1 portrait) #}
                    {if:elseif imagearrange == "q1h2"}
                        {if images_start:count == 1}
                            &lt;figure class="q1"&gt;
                                &lt;img src="{url:2-3-landscape}"&gt;
                            &lt;/figure&gt;
                        {if:elseif images_start:count == 2}
                            &lt;figure class="h2"&gt;
                                &lt;img src="{url:1-3-portrait}"&gt;
                            &lt;/figure&gt;
                        {/if}
                {# C1 (1 portrait / 1 landscape) #}
                    {if:elseif imagearrange == "h1q2"}
                        {if images_start:count == 1}
                            &lt;figure class="h1"&gt;
                                &lt;img src="{url:1-3-portrait}"&gt;
                            &lt;/figure&gt;
                        {if:elseif images_start:count == 2}
                            &lt;figure class="q2"&gt;
                                &lt;img src="{url:2-3-quer}"&gt;
                            &lt;/figure&gt;
                        {/if}
                {# D (3 portraite) #}
</code></pre>

<p>now I want to bring this functionality to craft – and I already checked out how to check for the fields values e.g. {if:elseif imagearrange == "h1q2"}. </p>

<p>but: I can't figure out how to check for the 1st, the 2nd, the 3rd image in an asset field, like {if images_start:count == 1} in ee. </p>

<p>since craft seems in many ways more efficent than ee maybe this would be solved completely different and I am absolutely open to learn new ways of doing this.</p>

<p>thank you very much!</p>

<craft3><assets><conditional>
how to check for the 2nd, 3rd, 4th… image in an asset's field
# how to check for the 2nd, 3rd, 4th… image in an asset's field

(Asked by: username_0 on 2020-02-22)

I am currently "translating" our current website, which runs on the lastest expressionengine, to craft. we use imagegrids that are arranged by css. 
so in an entrie's pulldown field choose between several grids (named q1, q1q2, etc.) and checked via conditionals in the code to know how to style the images and to give them the right "transformations"/sizes:
{# Imagegrid #}
    
        {images_start}
            {images_start:file}
                {# A (1 landscape) #}
                {if imagearrange == "q1"}
                    {if images_start:count == 1}
                        
                            
                        
                    {/if}
                {# B (2 landscape) #}
                {if:elseif imagearrange == "q1q2"}
                    {if images_start:count == 1}
                        
                            
                           
                    {if:elseif images_start:count == 2}
                        
                            
                        
                    {/if}
                {# C (1 landscape / 1 portrait) #}
                    {if:elseif imagearrange == "q1h2"}
                        {if images_start:count == 1}
                            
                                
                            
                        {if:elseif images_start:count == 2}
                            
                                
                            
                        {/if}
                {# C1 (1 portrait / 1 landscape) #}
                    {if:elseif imagearrange == "h1q2"}
                        {if images_start:count == 1}
                            
                                
                            
                        {if:elseif images_start:count == 2}
                            
                                
                            
                        {/if}
                {# D (3 portraite) #}

now I want to bring this functionality to craft – and I already checked out how to check for the fields values e.g. {if:elseif imagearrange == "h1q2"}. 
but: I can't figure out how to check for the 1st, the 2nd, the 3rd image in an asset field, like {if images_start:count == 1} in ee. 
since craft seems in many ways more efficent than ee maybe this would be solved completely different and I am absolutely open to learn new ways of doing this.
thank you very much!

**Tags:** craft3, assets, conditional

---

## 1 answers

### Answer by username_1 on 2020-02-24. Score: 1

Since in Craft you will loop over an Assets field, you could use the loop.index variable: <https://twig.symfony.com/doc/2.x/tags/for.html> to check for the nth iteration.

> **Comments:**
> **username_0**: but how could I use the loop.index compared to `{if images_start:count == 1}X{if:elseif images_start:count == 2}Y{/if}`? or do I need a different direction for whole code construct?  
> **username_1**: The [divisible by](https://twig.symfony.com/doc/2.x/tests/divisibleby.html) test comes handy:   `{% if loop.index is divisible by(3) %}  This is the 3rd item  {% endif %}`  

---

