Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

[1.2.X] Fixed #10545 -- Mentioned that template context variables onl…

…y exist in the scope of th block in which they're assigned. Thanks to yaniv.haber for the report and timo for the patch.

Backport of [14350] from trunk.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit da5f6ef9e04e6f5d43b4d93699cd56c82f7c2917 1 parent 1826039
Gabriel Hurley authored
Showing with 8 additions and 1 deletion.
  1. +8 −1 docs/howto/custom-template-tags.txt
9 docs/howto/custom-template-tags.txt
@@ -790,7 +790,7 @@ difference between this case and the previous ``inclusion_tag`` example.
Setting a variable in the context
-The above example simply output a value. Generally, it's more flexible if your
+The above examples simply output a value. Generally, it's more flexible if your
template tags set template variables instead of outputting values. That way,
template authors can reuse the values that your template tags create.
@@ -816,6 +816,13 @@ Here's how you'd use this new version of the tag:
{% current_time "%Y-%M-%d %I:%M %p" %}<p>The time is {{ current_time }}.</p>
+.. admonition:: Variable scope in context
+ Any variable set in the context will only be available in the same ``block``
+ of the template in which it was assigned. This behaviour is intentional;
+ it provides a scope for variables so that they don't conflict with
+ context in other blocks.
But, there's a problem with ``CurrentTimeNode2``: The variable name
``current_time`` is hard-coded. This means you'll need to make sure your
template doesn't use ``{{ current_time }}`` anywhere else, because the

0 comments on commit da5f6ef

Please sign in to comment.
Something went wrong with that request. Please try again.