Looking to do something like this:

{% for image in block.images %}
    <img src="{{ image.url }}" data-index="{{ image.index }}">
{% 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


This will do it:

{% for key, image in block.images %}
    {{ key }} - <img src="{{ image.url }}" data-index="{{ key }}">
{% endfor %}

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.