merged with 2.3-maintenance
[jinja2.git] / docs / tricks.rst
index 051c6fa5511239fbf5b81b13ead631a7ffdfcb0a..566575e52d94764361c0c2b44ecbe999ec935225 100644 (file)
@@ -79,3 +79,22 @@ sense to defined a default for that variable::
     {% endfor %}
     </ul>
     ...
+
+.. _accessing-the-parent-loop:
+
+Accessing the parent Loop
+-------------------------
+
+The special `loop` variable always points to the innermost loop.  If it's
+desired to have access to an outer loop it's possible to alias it::
+
+    <table>
+    {% for row in table %}
+      <tr>
+      {% set rowloop = loop %}
+      {% for cell in row %}
+        <td id="cell-{{ rowloop.index }}-{{ loop.index }}>{{ cell }}</td>
+      {% endfor %}
+      </tr>
+    {% endfor %}
+    </table>