Added missing reference.
[jinja2.git] / docs / switching.rst
index 98303fe79d688fc3d483e20461e6e6e1b3862cfd..ba3cfb1ff4f1c2aa34cceffb41107b54503c4c52 100644 (file)
@@ -79,6 +79,10 @@ instead.  Includes no longer import macros and variable assignments, for
 that the new `import` tag is used.  This concept is explained in the
 :ref:`import` documentation.
 
+Another small change happened in the `for`-tag.  The special loop variable
+doesn't have a `parent` attribute, instead you have to alias the loop
+yourself.  See :ref:`accessing-the-parent-loop` for more details.
+
 
 Django
 ------
@@ -170,6 +174,34 @@ operator.  Here are some examples::
         hmm. {{ user.username|e }} looks pretty normal
     {% endif %}
 
+Loops
+~~~~~
+
+For loops work very similar to Django, the only incompatibility is that in
+Jinja2 the special variable for the loop context is called `loop` and not
+`forloop` like in Django.
+
+Cycle
+~~~~~
+
+The ``{% cycle %}`` tag does not exist in Jinja because of it's implicit
+nature.  However you can achieve mostly the same by using the `cycle`
+method on a loop object.
+
+The following Django template::
+
+    {% for user in users %}
+        <li class="{% cycle 'odd' 'even' %}">{{ user }}</li>
+    {% endfor %}
+
+Would look like this in Jinja::
+
+    {% for user in users %}
+        <li class="{{ loop.cycle('odd', 'even') }}">{{ user }}</li>
+    {% endfor %}
+
+There is no equivalent of ``{% cycle ... as variable %}``.
+
 
 Mako
 ----