Skip to content

Commit 8a8eafc

Browse files
committed
edit block assignment section
1 parent d6998ab commit 8a8eafc

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

docs/templates.rst

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,35 +1086,34 @@ Assignments use the `set` tag and can have multiple targets::
10861086
Block Assignments
10871087
~~~~~~~~~~~~~~~~~
10881088

1089-
.. versionadded:: 2.8
1089+
It's possible to use `set` as a block to assign the content of the block to a
1090+
variable. This can be used to create multi-line strings, since Jinja doesn't
1091+
support Python's triple quotes (``"""``, ``'''``).
10901092

1091-
Starting with Jinja 2.8, it's possible to also use block assignments to
1092-
capture the contents of a block into a variable name. This can be useful
1093-
in some situations as an alternative for macros. It can also be used to create
1094-
multiline strings instead of triple quotes (''' and """), which Jinja does not
1095-
support. In that case, instead of using an equals sign and a value, you just
1096-
write the variable name and then everything until ``{% endset %}`` is captured.
1093+
Instead of using an equals sign and a value, you only write the variable name,
1094+
and everything until ``{% endset %}`` is captured.
10971095

1098-
Example::
1096+
.. code-block:: jinja
10991097
11001098
{% set navigation %}
11011099
<li><a href="/">Index</a>
11021100
<li><a href="/downloads">Downloads</a>
11031101
{% endset %}
11041102
1105-
The `navigation` variable then contains the navigation HTML source.
1106-
1107-
.. versionchanged:: 2.10
1108-
1109-
Starting with Jinja 2.10, the block assignment supports filters.
1103+
Filters applied to the variable name will be applied to the block's content.
11101104

1111-
Example::
1105+
.. code-block:: jinja
11121106
11131107
{% set reply | wordwrap %}
11141108
You wrote:
11151109
{{ message }}
11161110
{% endset %}
11171111
1112+
.. versionadded:: 2.8
1113+
1114+
.. versionchanged:: 2.10
1115+
1116+
Block assignment supports filters.
11181117

11191118
.. _extends:
11201119

0 commit comments

Comments
 (0)