Skip to content

Commit

Permalink
Documented differences of cycling between Django and Jinja2.
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
mitsuhiko committed Jun 19, 2008
1 parent 74b5106 commit f288b7a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/switching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand Down

0 comments on commit f288b7a

Please sign in to comment.