1

I need a unique id for each table row. Something like this which does not work:

{% for row in block.buttons %}{{ row.id }}{% endfor %}

Is this possible?

Thanks!

1 Answer 1

1

Yes, this is possible using the Twig Loop variable. The following will add the current iteration of the loop.

{% for row in block.buttons %}
    {{ loop.index }}
{% endfor %}
2
  • 1
    Perfect. Thank you!
    – fodney
    Commented Feb 4, 2022 at 18:11
  • 1
    Beware that index starts at 1. If you need 0-indexed, use index0.
    – PWL
    Commented Feb 11, 2022 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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