@@ -396,7 +396,7 @@ clauses, as well as an ``{% else %}`` clause that will be displayed if all
previous conditions fail. These clauses are optional.
Boolean operators
^^^^^^^^^^^^^^^^^
"""""""""""""""""
:ttag:`if` tags may use ``and``, ``or`` or ``not`` to test a number of
variables or to negate a given variable::
@@ -438,9 +438,8 @@ them to indicate precedence, you should use nested :ttag:`if` tags.
:ttag:`if` tags may also use the operators ``==``, ``!=``, ``<``, ``>``,
``<=``, ``>=`` and ``in`` which work as follows:
``==`` operator
^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~
Equality. Example::
@@ -449,7 +448,7 @@ Equality. Example::
{% endif %}
``!=`` operator
^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~
Inequality. Example::
@@ -459,7 +458,7 @@ Inequality. Example::
{% endif %}
``<`` operator
^^^^^^^^^^^^^^
~~~~~~~~~~~~~~
Less than. Example::
@@ -468,7 +467,7 @@ Less than. Example::
{% endif %}
``>`` operator
^^^^^^^^^^^^^^
~~~~~~~~~~~~~~
Greater than. Example::
@@ -477,7 +476,7 @@ Greater than. Example::
{% endif %}
``<=`` operator
^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~
Less than or equal to. Example::
@@ -486,7 +485,7 @@ Less than or equal to. Example::
{% endif %}
``>=`` operator
^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~
Greater than or equal to. Example::
@@ -495,7 +494,7 @@ Greater than or equal to. Example::
{% endif %}
``in`` operator
^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~
Contained within. This operator is supported by many Python containers to test
whether the given value is in the container. The following are some examples
@@ -516,11 +515,10 @@ of how ``x in y`` will be interpreted::
{% endif %}
``not in`` operator
^^^^^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~~~~~
Not contained within. This is the negation of the ``in`` operator.
The comparison operators cannot be 'chained' like in Python or in mathematical
notation. For example, instead of using::
@@ -530,9 +528,8 @@ you should use::
{% if a > b and b > c %}
Filters
^^^^^^^
"""""""
You can also use filters in the :ttag:`if` expression. For example::
@@ -541,7 +538,7 @@ You can also use filters in the :ttag:`if` expression. For example::
{% endif %}
Complex expressions
^^^^^^^^^^^^^^^^^^^
"""""""""""""""""""
All of the above can be combined to form complex expressions. For such
expressions, it can be important to know how the operators are grouped when the
@@ -571,7 +568,6 @@ If you need different precedence, you will need to use nested :ttag:`if` tags.
Sometimes that is better for clarity anyway, for the sake of those who do not
know the precedence rules.
.. templatetag:: ifchanged
ifchanged
@@ -812,7 +808,6 @@ This would display as "It is the 4th of September".
It is {% now "SHORT_DATETIME_FORMAT" %}
You can also use the syntax ``{% now "Y" as current_year %}`` to store the
output (as a string) inside a variable. This is useful if you want to use
``{% now %}`` inside a template tag like :ttag:`blocktrans` for example::
@@ -831,7 +826,9 @@ regroup
Regroups a list of alike objects by a common attribute.
This complex tag is best illustrated by way of an example: say that "places" is a list of cities represented by dictionaries containing ``"name"``, ``"population"``, and ``"country"`` keys:
This complex tag is best illustrated by way of an example: say that "places" is
a list of cities represented by dictionaries containing ``"name"``,
``"population"``, and ``"country"`` keys:
.. code-block:: python
@@ -843,7 +840,8 @@ This complex tag is best illustrated by way of an example: say that "places" is