Answers.Body: <p>To better understand, do you want transform for all <strong>even</strong> iterations on the array? If so, Twig's <a href="http://twig.sensiolabs.org/doc/functions/cycle.html" rel="nofollow"><code>cycle</code></a> function should do what you want:</p>
  
  <pre><code>{% set asset = entry.portraits %}
  {% if asset | length %}
     {% for asset in entry.portraits %}
        {% set transform = cycle(['largeIndex', 'largeIndexHalf'], loop.index0) %}
        &lt;div class="item"&gt;&lt;img src="{{ asset.getUrl(transform) }}" /&gt;&lt;/div&gt;
     {% endfor %}
  {% endif %}
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>Rereading the question and Brandon's answer, I may have misinterpreted that you do indeed <em>just</em> want the 2nd and 4th image. I'll leave my answer for posterity for people looking to do an even / odd thing though.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-12T16:30:03.567Z
Answers.LastActivityDate: 2015-03-12T16:59:23.950Z
Answers.LastEditDate: 2015-03-12T16:59:23.950Z
Answers.UserDisplayName: Peter Tell
Answers.Body: <p>You could do that like so:</p>
  
  <pre><code>{% for asset in entry.portraits %}
      {% if loop.index == 2 or loop.index == 4 %}
          {% set transform = 'largeIndexHalf' %}
      {% else %}
          {% set transform = 'largeIndex' %}
      {% endif %}
      &lt;div class="item"&gt;&lt;img src="{{ asset.getUrl(transform) }}" /&gt;&lt;/div&gt;
  {% endfor %}
  </code></pre>
  
  <p>or more simply (making use of the <a href="http://twig.sensiolabs.org/doc/templates.html#containment-operator">containment operator</a> (<code>in</code>) and the ternary operator (<code>? :</code>):</p>
  
  <pre><code>{% for asset in entry.portraits %}
      {% set transform = loop.index in [2, 4] ? 'largeIndexHalf' : 'largeIndex' %}
      &lt;div class="item"&gt;&lt;img src="{{ asset.getUrl(transform) }}" /&gt;&lt;/div&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-12T21:49:55.580Z
Answers.Text: Works a treat. Thank you. Example here: http://alisilversteinportraits.com/
Answers.UserDisplayName: Niall Thompson
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-12T16:29:24.137Z
Answers.LastActivityDate: 2015-03-12T16:29:24.137Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I have a masonry type image grid layout and I need to specify a different image transform for just the 2nd and fourth images in this grid.</p>
  
  <p>Does the image ID relate to the order or to the specific image? How could I include a conditional in my code to output the largeIndexHalf image transform for the 2nd and 4th image?</p>
  
  <pre><code>{% set asset = entry.portraits %}
  {% if asset | length %}
  {% for asset in entry.portraits %}
  &lt;div class="item"&gt;&lt;img src="{{ asset.getUrl('largeIndex') }}" /&gt;&lt;/div&gt;
  {% endfor %}
  {% endif %}
  </code></pre>
  
Tags: <assets><image-transforms>
Title: Transform different image if specific id or order
ThreadText: # Transform different image if specific id or order
  
  (Asked by: username_0 on 2015-03-12)
  
  I have a masonry type image grid layout and I need to specify a different image transform for just the 2nd and fourth images in this grid.
  
  Does the image ID relate to the order or to the specific image? How could I include a conditional in my code to output the largeIndexHalf image transform for the 2nd and 4th image?
  
  ```
  {% set asset = entry.portraits %}
  {% if asset | length %}
  {% for asset in entry.portraits %}
  <div class="item"><img src="{{ asset.getUrl('largeIndex') }}" /></div>
  {% endfor %}
  {% endif %}
  
  ```
  
  **Tags:** assets, image-transforms
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2015-03-12. Score: 6 | Accepted answer
  
  You could do that like so:
  
  ```
  {% for asset in entry.portraits %}
      {% if loop.index == 2 or loop.index == 4 %}
          {% set transform = 'largeIndexHalf' %}
      {% else %}
          {% set transform = 'largeIndex' %}
      {% endif %}
      <div class="item"><img src="{{ asset.getUrl(transform) }}" /></div>
  {% endfor %}
  
  ```
  
  or more simply (making use of the [containment operator](http://twig.sensiolabs.org/doc/templates.html#containment-operator) (`in`) and the ternary operator (`? :`):
  
  ```
  {% for asset in entry.portraits %}
      {% set transform = loop.index in [2, 4] ? 'largeIndexHalf' : 'largeIndex' %}
      <div class="item"><img src="{{ asset.getUrl(transform) }}" /></div>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Works a treat. Thank you. Example here: http://alisilversteinportraits.com/  
  
  ---
  
  ### Answer by username_1 on 2015-03-12. Score: 3
  
  To better understand, do you want transform for all **even** iterations on the array? If so, Twig's [`cycle`](http://twig.sensiolabs.org/doc/functions/cycle.html) function should do what you want:
  
  ```
  {% set asset = entry.portraits %}
  {% if asset | length %}
     {% for asset in entry.portraits %}
        {% set transform = cycle(['largeIndex', 'largeIndexHalf'], loop.index0) %}
        <div class="item"><img src="{{ asset.getUrl(transform) }}" /></div>
     {% endfor %}
  {% endif %}
  
  ```
  
  **Edit**
  
  Rereading the question and username_2's answer, I may have misinterpreted that you do indeed *just* want the 2nd and 4th image. I'll leave my answer for posterity for people looking to do an even / odd thing though.
  
  
  ---
  
  