0
Q:

how to for loop twig

loop.index	    The current iteration of the loop. (1 indexed)
loop.index0	    The current iteration of the loop. (0 indexed)
loop.revindex	The number of iterations from the end of the loop (1 indexed)
loop.revindex0	The number of iterations from the end of the loop (0 indexed)
loop.first	    True if first iteration
loop.last	    True if last iteration
loop.length	    The number of items in the sequence
loop.parent	    The parent context

{% for user in users %}
    {{ loop.index }} - {{ user.username }}
{% endfor %}
1
{% for user in users %}
    {{ loop.index }} - {{ user.username }}
{% endfor %}
0
{% for i in 0..10 %}
    * {{ i }}
{% endfor %}
0
{% for letter in 'a'..'z' %}
    * {{ letter }}
{% endfor %}
0

New to Communities?

Join the community