access loop.index when within another loop in twig

In fact there’s no need to set an extra variable. For two nested loops twig provides the so called parent.loop context.

To access the parents loop.index do this:

{% for i in range(0, 3) %}
    {% for j in range(0, 9) %}
        {{ loop.parent.loop.index + loop.index }}
    {% endfor %}
{% endfor %}

Also refer to the documentation

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)