Target second (or nth) element in a for loop I'm trying to show content for only the second entry in a for loop, but can't find any info on how to do specifically this. I'd like to do something like the below.

{% for relatedImage in entry.relatedImages %}
    {% for images in relatedImage.image %}
        &lt;div&gt;
            &lt;a href="{{ relatedImage.url }}"&gt;
                &lt;img src="{{ images.getUrl('default') }}" alt="{{ relatedImage.title }}" width="{{ images.getWidth('default') }}" height="{{ images.getHeight('default') }}" /&gt;
             &lt;/a&gt;{% if loop.index == 2 %}&lt;div&gt;&lt;h2&gt;Welcome!&lt;/h2&gt;&lt;/div&gt;{% endif %}
         &lt;/div&gt;
    {% endfor %}
{% endfor %}


Any ideas?
It's not working because you're using loop.index in the context of the inner loop.

Based on your comment, there will only ever be one images selected, so loop.index will never be 2.

If you don't want to move the loop.index check to the outer loop, then a simple counter will work:

{% set counter = 0 %}

{% for relatedImage in entry.relatedImages %}
    {% set counter = counter + 1 %}

    {% for images in relatedImage.image %}
        &lt;div&gt;
            &lt;a href="{{ relatedImage.url }}"&gt;
                &lt;img src="{{ images.getUrl('default') }}" alt="{{ relatedImage.title }}" width="{{ images.getWidth('default') }}" height="{{ images.getHeight('default') }}" /&gt;
             &lt;/a&gt;{% if counter == 2 %}&lt;div&gt;&lt;h2&gt;Welcome!&lt;/h2&gt;&lt;/div&gt;{% endif %}
         &lt;/div&gt;
    {% endfor %}


{% endfor %}