views:

181

answers:

1

Is it possible to access the forloop.counter for the outermost for loop in the following template in Django:

{% for outerItem in outerItems %}
    {% for item in items%}
        <div>{{ forloop.counter }}.&nbsp;{{ item }}</div>
    {% endfor %}
{% endfor %}

forloop.counter returns the innermost for loop's counter in the above example

+2  A: 

You can use forloop.parentloop to get to the outer forloop, so in your case {{forloop.parentloop.counter}}.

Tom