summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2019-10-18 11:23:59 -0700
committerDavid Lord <davidism@gmail.com>2019-10-18 11:23:59 -0700
commita55428847565d2d62ffa83b95eff354b0d419ff2 (patch)
tree37c714ad56cf0b00103b28421e8ba5ff3afac3f0 /docs
parentd2bf5821753d42e97d94d15aa0aedc20971b6030 (diff)
downloadjinja2-a55428847565d2d62ffa83b95eff354b0d419ff2.tar.gz
format expression docs
Diffstat (limited to 'docs')
-rw-r--r--docs/templates.rst74
1 files changed, 37 insertions, 37 deletions
diff --git a/docs/templates.rst b/docs/templates.rst
index 09ac799..f1f3c2f 100644
--- a/docs/templates.rst
+++ b/docs/templates.rst
@@ -1174,24 +1174,24 @@ Literals
The simplest form of expressions are literals. Literals are representations
for Python objects such as strings and numbers. The following literals exist:
-"Hello World":
+``"Hello World"``
Everything between two double or single quotes is a string. They are
useful whenever you need a string in the template (e.g. as
arguments to function calls and filters, or just to extend or include a
template).
-42 / 123_456:
+``42`` / ``123_456``
Integers are whole numbers without a decimal part. The '_' character
can be used to separate groups for legibility.
-42.23 / 42.1e2 / 123_456.789:
+``42.23`` / ``42.1e2`` / ``123_456.789``
Floating point numbers can be written using a '.' as a decimal mark.
They can also be written in scientific notation with an upper or
lower case 'e' to indicate the exponent part. The '_' character can
be used to separate groups for legibility, but cannot be used in the
exponent part.
-['list', 'of', 'objects']:
+``['list', 'of', 'objects']``
Everything between two brackets is a list. Lists are useful for storing
sequential data to be iterated over. For example, you can easily
create a list of links using lists and tuples for (and with) a for loop::
@@ -1203,20 +1203,20 @@ for Python objects such as strings and numbers. The following literals exist:
{% endfor %}
</ul>
-('tuple', 'of', 'values'):
+``('tuple', 'of', 'values')``
Tuples are like lists that cannot be modified ("immutable"). If a tuple
only has one item, it must be followed by a comma (``('1-tuple',)``).
Tuples are usually used to represent items of two or more elements.
See the list example above for more details.
-{'dict': 'of', 'key': 'and', 'value': 'pairs'}:
+``{'dict': 'of', 'key': 'and', 'value': 'pairs'}``
A dict in Python is a structure that combines keys and values. Keys must
be unique and always have exactly one value. Dicts are rarely used in
templates; they are useful in some rare cases such as the :func:`xmlattr`
filter.
-true / false:
- true is always true and false is always false.
+``true`` / ``false``
+ ``true`` is always true and ``false`` is always false.
.. admonition:: Note
@@ -1234,73 +1234,73 @@ Math
Jinja allows you to calculate with values. This is rarely useful in templates
but exists for completeness' sake. The following operators are supported:
-\+
+``+``
Adds two objects together. Usually the objects are numbers, but if both are
strings or lists, you can concatenate them this way. This, however, is not
the preferred way to concatenate strings! For string concatenation, have
a look-see at the ``~`` operator. ``{{ 1 + 1 }}`` is ``2``.
-\-
+``-``
Subtract the second number from the first one. ``{{ 3 - 2 }}`` is ``1``.
-/
+``/``
Divide two numbers. The return value will be a floating point number.
``{{ 1 / 2 }}`` is ``{{ 0.5 }}``.
-//
+``//``
Divide two numbers and return the truncated integer result.
``{{ 20 // 7 }}`` is ``2``.
-%
+``%``
Calculate the remainder of an integer division. ``{{ 11 % 7 }}`` is ``4``.
-\*
+``*``
Multiply the left operand with the right one. ``{{ 2 * 2 }}`` would
return ``4``. This can also be used to repeat a string multiple times.
``{{ '=' * 80 }}`` would print a bar of 80 equal signs.
-\**
+``**``
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 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 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 than the right hand side.
-<=
- `true` if the left hand side is lower or equal to the right hand side.
+``<=``
+ ``true`` if the left hand side is lower or equal to the right hand side.
Logic
~~~~~
-For `if` statements, `for` filtering, and `if` expressions, it can be useful to
+For ``if`` statements, ``for`` filtering, and ``if`` expressions, it can be useful to
combine multiple expressions:
-and
+``and``
Return true if the left and the right operand are true.
-or
+``or``
Return true if the left or the right operand are true.
-not
+``not``
negate a statement (see below).
-(expr)
- group an expression.
+``(expr)``
+ Parentheses group an expression.
.. admonition:: Note
@@ -1316,30 +1316,30 @@ Other Operators
The following operators are very useful but don't fit into any of the other
two categories:
-in
+``in``
Perform a sequence / mapping containment test. Returns true if the left
operand is contained in the right. ``{{ 1 in [1, 2, 3] }}`` would, for
example, return true.
-is
+``is``
Performs a :ref:`test <tests>`.
-\|
+``|``
Applies a :ref:`filter <filters>`.
-~
+``~``
Converts all operands into strings and concatenates them.
``{{ "Hello " ~ name ~ "!" }}`` would return (assuming `name` is set
to ``'John'``) ``Hello John!``.
-()
+``()``
Call a callable: ``{{ post.render() }}``. Inside of the parentheses you
can use positional arguments and keyword arguments like in Python:
``{{ post.render(user, full=true) }}``.
-. / []
+``.`` / ``[]``
Get an attribute of an object. (See :ref:`variables`)