Documented differences of cycling between Django and Jinja2.
authorArmin Ronacher <armin.ronacher@active-4.com>
Thu, 19 Jun 2008 07:41:56 +0000 (09:41 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Thu, 19 Jun 2008 07:41:56 +0000 (09:41 +0200)
--HG--
branch : trunk

docs/switching.rst

index 0c496317ca99f1addea3cf7ae1e47fe0661f6af6..ba3cfb1ff4f1c2aa34cceffb41107b54503c4c52 100644 (file)
@@ -181,6 +181,27 @@ 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
 ----