Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-24T19:01:09.763Z
Answers.Text: 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?
Answers.UserDisplayName: Matthias
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-25T07:44:22.833Z
Answers.Text: 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 %}`
Answers.UserDisplayName: gioppe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-24T09:24:21.907Z
Answers.LastActivityDate: 2020-02-24T09:24:21.907Z
Answers.UserDisplayName: gioppe
Body: <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>
  
Tags: <craft3><assets><conditional>
Title: how to check for the 2nd, 3rd, 4th… image in an asset's field
ThreadText: # 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 #}
      <figure class="grid {imagearrange}">
          {images_start}
              {images_start:file}
                  {# A (1 landscape) #}
                  {if imagearrange == "q1"}
                      {if images_start:count == 1}
                          <figure class="q1">
                              <img src="{url:1-1-landscape}">
                          </figure>
                      {/if}
                  {# B (2 landscape) #}
                  {if:elseif imagearrange == "q1q2"}
                      {if images_start:count == 1}
                          <figure class="q1">
                              <img src="{url:1-2-landscape}">
                          </figure>   
                      {if:elseif images_start:count == 2}
                          <figure class="q2">
                              <img src="{url:1-2-landscape}">
                          </figure>
                      {/if}
                  {# C (1 landscape / 1 portrait) #}
                      {if:elseif imagearrange == "q1h2"}
                          {if images_start:count == 1}
                              <figure class="q1">
                                  <img src="{url:2-3-landscape}">
                              </figure>
                          {if:elseif images_start:count == 2}
                              <figure class="h2">
                                  <img src="{url:1-3-portrait}">
                              </figure>
                          {/if}
                  {# C1 (1 portrait / 1 landscape) #}
                      {if:elseif imagearrange == "h1q2"}
                          {if images_start:count == 1}
                              <figure class="h1">
                                  <img src="{url:1-3-portrait}">
                              </figure>
                          {if:elseif images_start:count == 2}
                              <figure class="q2">
                                  <img src="{url:2-3-quer}">
                              </figure>
                          {/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 %}`  
  
  ---
  
  