<p>This will do it:</p>

<pre><code>{% for key, image in block.images %}
    {{ key }} - &lt;img src="{{ image.url }}" data-index="{{ key }}"&gt;
{% endfor %}
</code></pre>

<p>Keep in mind that's a 0 based array, so the first image will output 0, the 2nd 1, etc.</p>

CC BY-SA 3.0
2014-12-11T03:15:38.153Z
2014-12-11T04:13:35.960Z
2014-12-11T04:13:35.960Z
Brad Bell
<p>Looking to do something like this:</p>

<pre><code>{% for image in block.images %}
    &lt;img src="{{ image.url }}" data-index="{{ image.index }}"&gt;
{% endfor %}
</code></pre>

<p>This seems like it should be easy and I feel like I've done it before, however I can't seem to figure it out. Thanks</p>

<templating><assets>
How do I display the index of the asset in assets loop?
# How do I display the index of the asset in assets loop?

(Asked by: username_0 on 2014-12-11)

Looking to do something like this:
{% for image in block.images %}
    
{% endfor %}

This seems like it should be easy and I feel like I've done it before, however I can't seem to figure it out. Thanks

**Tags:** templating, assets

---

## 1 answers

### Answer by username_1 on 2014-12-11. Score: 3 | Accepted answer

This will do it:
{% for key, image in block.images %}
    {{ key }} - 
{% endfor %}

Keep in mind that's a 0 based array, so the first image will output 0, the 2nd 1, etc.


---

