twig get index in for loop code example
Example 1: foreach twig
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}
Example 2: twig loop
{% for user in users %}
{{ loop.index }} - {{ user.username }}
{% endfor %}
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}
{% for user in users %}
{{ loop.index }} - {{ user.username }}
{% endfor %}