Skip to content
Myr

Documented differences of cycling between Django and Jinja2.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 74b5106 · Browse files · 1 file+21 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+21 added−0 removed

  • other:+21 added−0 removed

1 file+21 added−0 removed

modified:docs/switching.rst+21 added
179 unmodified lines
180For loops work very similar to Django, the only incompatibility is that in181Jinja2 the special variable for the loop context is called `loop` and not182`forloop` like in Django.183184Cycle185~~~~~186187The ``{% cycle %}`` tag does not exist in Jinja because of it's implicit188nature. However you can achieve mostly the same by using the `cycle`189method on a loop object.190191The following Django template::192193 {% for user in users %}194 <li class="{% cycle 'odd' 'even' %}">{{ user }}</li>195 {% endfor %}196197Would look like this in Jinja::198199 {% for user in users %}200 <li class="{{ loop.cycle('odd', 'even') }}">{{ user }}</li>201 {% endfor %}202203There is no equivalent of ``{% cycle ... as variable %}``.204205206Mako207----208209.. highlight:: html+mako
33 unmodified lines