[Answer]-Django Template: How to use parent variable in nested for loop

1👍

really you should do

context = {"rounds":[["match1","match2","match3"],["match2","match1"]]

{% for round in rounds %}
   <div id="round_{{forloop.counter0}}">
      {% for match in round %}
          I am match {{forloop.counter1}}
          in round {{forloop.counter0 }}
      {% endfor %}
   </div>
{% endfor %}

I think thats right at least …

iirc counter0 is the outermost forloop ,counter1 is the next inner (I think you can go as far as 9)

counter refers to the current one

Leave a comment