{% include "render_box.html" %}
{% endfor %}
- The included template ``render_box.html`` is not able to access
- `box` in Jinja 2.0, but in Jinja 2.1.
+ The included template ``render_box.html`` is *not* able to access
+ `box` in Jinja 2.0. As of Jinja 2.1 ``render_box.html`` *is* able
+ to do so.
.. _expressions:
//
Divide two numbers and return the truncated integer result.
- ``{{ 20 / 7 }}`` is ``2``.
+ ``{{ 20 // 7 }}`` is ``2``.
%
Calculate the remainder of an integer division. ``{{ 11 % 7 }}`` is ``4``.
Raise the left operand to the power of the right operand. ``{{ 2**3 }}``
would return ``8``.
+Comparisons
+~~~~~~~~~~~
+
+==
+ Compares two objects for equality.
+
+!=
+ Compares two objects for inequality.
+
+>
+ `true` if the left hand side is greater than the right hand side.
+
+>=
+ `true` if the left hand side is greater or equal to the right hand side.
+
+<
+ `true` if the left hand side is lower than the right hand side.
+
+<=
+ `true` if the left hand side is lower or equal to the right hand side.
+
Logic
~~~~~
To use placeholders you can use the `format` filter::
{{ _('Hello %(user)s!')|format(user=user.username) }}
- or
- {{ _('Hello %s')|format(user.username) }}
For multiple placeholders always use keyword arguments to `format` as other
languages may not use the words in the same order.
+.. versionchanged:: 2.5
+
+If newstyle gettext calls are activated (:ref:`newstyle-gettext`), using
+placeholders is a lot easier:
+
+.. sourcecode:: html+jinja
+
+ {{ gettext('Hello World!') }}
+ {{ gettext('Hello %(name)s!', name='World') }}
+ {{ ngettext('%(num)d apple', '%(num)d apples', apples|count) }}
+
+Note that the `ngettext` function's format string automatically recieves
+the count as `num` parameter additionally to the regular parameters.
+
Expression Statement
~~~~~~~~~~~~~~~~~~~~