title: Django template tags {{for/empty}} for loop variable
body: <p>To generate a set of Javascript variables with the relevant parameters from my Django application I have two nested for loops:</p>
  
  <pre><code>&lt;script&gt;
  {% for model in models %} 
      {% for item in model.attribute|slice:":3" %}
          {% if forloop.first %} 
              var js_variable{{ forloop.parentloop.counter0 }} = [
          {% endif %}
              '{{ item.attribute }}' ,
          {% if forloop.last %}
              {{ item.attribute }} ]
      {% empty %}
          var js_variable{{ forloop.parentloop.counter0 }} = []
      {% endfor %}
  {% endfor %}
  
  ....code that gets unhappy when js_variable[n] doesn't exist.....
  
  &lt;/script&gt;
  </code></pre>
  
  <p>When <code>{% empty %}</code> occurs it doesn't seem to have the access to the <code>{{ forloop.parentloop. counter0 }}</code> variable, and so the variable name <code>js_variable[n]</code> is printed incorrectly as <code>js_variable</code> (without the number otherwise provided by the counter), and later code complains.</p>
  
  <p>Is it the case that this variable won't be available in the <code>{{ empty }}</code> tag?</p>