Skip to content

Commit

Permalink
Added a note for #657
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jan 12, 2017
1 parent f30f5d8 commit 9574abe
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/templates.rst
Expand Up @@ -1515,6 +1515,24 @@ are equivalent::
{{ foo }}
{% endwith %}

An important note on scoping here. In Jinja versions before 2.9 the
behavior of referencing one variable to another had some unintended
consequences. In particular one variable could refer to another defined
in the same with block's opening statement. This caused issues with the
cleaned up scoping behavior and has since been improved. In particular
in newer Jinja2 versions the following code always refers to the variable
`a` from outside the `with` block::

{% with a={}, b=a.attribute %}...{% endwith %}

In earlier Jinja versions the `b` attribute would refer to the results of
the first attribute. If you depend on this behavior you can rewrite it to
use the ``set`` tag::

{% with a={} %}
{% set b = a.attribute %}
{% endwith %}

.. admonition:: Extension

In older versions of Jinja (before 2.9) it was required to enable this
Expand Down

0 comments on commit 9574abe

Please sign in to comment.