Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10545 -- Mentioned that template context variables are scoped …

…to the block in which they're assigned. Thanks to yaniv.haber for the report and timo for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14350 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9facaec719f3605c50d0188f95d979a692bdf8f9 1 parent 321e48f
authored

Showing 1 changed file with 8 additions and 1 deletion. Show diff stats Hide diff stats

  1. 9  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.
790 790
 Setting a variable in the context
791 791
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
792 792
 
793  
-The above example simply output a value. Generally, it's more flexible if your
  793
+The above examples simply output a value. Generally, it's more flexible if your
794 794
 template tags set template variables instead of outputting values. That way,
795 795
 template authors can reuse the values that your template tags create.
796 796
 
@@ -816,6 +816,13 @@ Here's how you'd use this new version of the tag:
816 816
 
817 817
     {% current_time "%Y-%M-%d %I:%M %p" %}<p>The time is {{ current_time }}.</p>
818 818
 
  819
+.. admonition:: Variable scope in context
  820
+
  821
+    Any variable set in the context will only be available in the same ``block``
  822
+    of the template in which it was assigned. This behaviour is intentional;
  823
+    it provides a scope for variables so that they don't conflict with
  824
+    context in other blocks.
  825
+
819 826
 But, there's a problem with ``CurrentTimeNode2``: The variable name
820 827
 ``current_time`` is hard-coded. This means you'll need to make sure your
821 828
 template doesn't use ``{{ current_time }}`` anywhere else, because the

0 notes on commit 9facaec

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