Switching docs tweaks
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Adam Chainz · committed by Adam Chainz · parent c97fa10 · Browse files · 1 file·+20 added−21 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+20 added−21 removed
- other:+20 added−21 removed
Provenance
- Commit
382ee70- Tree
1c4f9cb- Author
Adam Chainz <adam@adamj.eu>- Committer
Adam Chainz <adam@adamj.eu>- Parent
c97fa10
1 file changed+20 added−21 removed
modified:docs/switching.rst+20 added-21 removed
98 unmodified lines99 100 Method Calls101 ~~~~~~~~~~~~102 103-In Django method calls work implicitly. With Jinja2 you have to specify that104-you want to call an object. Thus this Django code::103+In Django method calls work implicitly; with Jinja2 you have to specify that104+you want to call a method explicitly. Thus this Django code::105 106 {% for page in user.get_created_pages %}107 ...108 {% endfor %}109- 110-will look like this in Jinja::109 110+...looks like this in Jinja::111+112 {% for page in user.get_created_pages() %}113 ...114 {% endfor %}115 116-This allows you to pass variables to the function which is also used for macros117-which is not possible in Django.116+This allows you to pass variables to the method, which is not possible in117+Django. This syntax is also used for macros.118 119 Conditions120 ~~~~~~~~~~121 36 unmodified lines158 looks like this in Jinja2::159 160 {{ items|join(', ') }}161 162-In fact it's a bit more verbose but it allows different types of arguments -162+It is a bit more verbose, but it allows different types of arguments -163 including variables - and more than one of them.164 165 Tests166 ~~~~~9 unmodified lines176 177 Loops178 ~~~~~179 180-For loops work very similar to Django. Notably, in Jinja2 the special variable for 181-the loop context is called `loop` and not `forloop` like in Django.180+For loops work very similarly to Django, but notably the Jinja2 special181+variable for the loop context is called `loop`, not `forloop` as in Django.182 183-In addition, the Django `empty` argument is called `else` in Jinja2. For example, the184-Django template::183+In addition, the Django `empty` argument is called `else` in Jinja2. For184+example, the Django template::185 186 {% for item in items %}187 {{ item }}188 {% empty %}189 No items!190 {% endfor %}191 192-would be handled in Jinja2 as::192+...looks like this in Jinja2::193 194 {% for item in items %}195 {{ item }}196 {% else %}2 unmodified lines199 200 Cycle201 ~~~~~202 203-The ``{% cycle %}`` tag does not exist in Jinja because of it's implicit204-nature. However you can achieve mostly the same by using the `cycle`205-method on a loop object.203+The ``{% cycle %}`` tag does not exist in Jinja2; however, you can achieve the204+same output by using the `cycle` method on the loop context special variable.205 206 The following Django template::207 208 {% for user in users %}209 <li class="{% cycle 'odd' 'even' %}">{{ user }}</li>210 {% endfor %}211 213-Would look like this in Jinja::212+...looks like this in Jinja2::213 214 {% for user in users %}215 <li class="{{ loop.cycle('odd', 'even') }}">{{ user }}</li>216 {% endfor %}12 unmodified lines229 .. sourcecode:: python230 231 env = Environment('<%', '%>', '${', '}', '<%doc>', '</%doc>', '%', '##')232 234-Once the environment is configured like that Jinja2 should be able to interpret235-a small subset of Mako templates. Jinja2 does not support embedded Python code236-so you would have to move that out of the template. The syntax for defs (in237-Jinja2 defs are called macros) and template inheritance is different too. The238-following Mako template::233+With an environment configured like that, Jinja2 should be able to interpret234+a small subset of Mako templates. Jinja2 does not support embedded Python235+code, so you would have to move that out of the template. The syntax for defs236+(which are called macros in Jinja2) and template inheritance is different too.237+The following Mako template::238 239 <%inherit file="layout.html" />240 <%def name="title()">Page Title</%def>241 <ul>16 unmodified lines