foreach twig code example
Example 1: twig foreach
{% for key, value in array %}
{{ key }}: {{ value }}
{% endfor %}
Example 2: foreach twig
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}
Example 3: twig for
<ul>
{% for key, user in users %}
<li>{{ key }}: {{ user.username|e }}</li>
{% endfor %}
</ul>
Example 4: twig loop variables
{% for user in users %}
{{ loop.index }} - {{ user.username }}
{% endfor %}
Example 5: how to for loop twig
{% for i in 0..10 %}
* {{ i }}
{% endfor %}
Example 6: how to for loop twig
{% for letter in 'a'..'z' %}
* {{ letter }}
{% endfor %}