X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=docs%2Ftemplates.rst;h=a4a7d30324b313c6e47dd04e08ba3db3e5854448;hb=6ae1285fa5b0a5ae6c1a90942adbb6262d4ae51e;hp=26234e01d88943135327f41d6dd4c356c7e115ea;hpb=752ba7f0d9831fb79cde22c1ceb678f79b16adce;p=jinja2.git diff --git a/docs/templates.rst b/docs/templates.rst index 26234e0..a4a7d30 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -883,8 +883,9 @@ Here two examples:: {% 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: @@ -971,7 +972,7 @@ but exists for completeness' sake. The following operators are supported: // 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``. @@ -985,6 +986,27 @@ but exists for completeness' sake. The following operators are supported: 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 ~~~~~ @@ -1239,12 +1261,24 @@ For example you can print a translated string easily this way:: 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 ~~~~~~~~~~~~~~~~~~~~