From: Armin Ronacher Date: Thu, 12 Jan 2017 15:00:02 +0000 (+0100) Subject: Added a note for #657 X-Git-Tag: 2.9.5~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9574abe564031c7f2034bfce22ed59a39d23948b;p=thirdparty%2Fjinja.git Added a note for #657 --- diff --git a/docs/templates.rst b/docs/templates.rst index fce59c7b..236590f2 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -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