Transform different image if specific id or order 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 %}
&lt;div class="item"&gt;&lt;img src="{{ asset.getUrl('largeIndex') }}" /&gt;&lt;/div&gt;
{% endfor %}
{% endif %}
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 %}
    &lt;div class="item"&gt;&lt;img src="{{ asset.getUrl(transform) }}" /&gt;&lt;/div&gt;
{% endfor %}


or more simply (making use of the containment operator (in) and the ternary operator (? :):

{% 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 %}