summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorGabriel Hurley <gabehr@gmail.com>2010-10-25 20:50:53 +0000
committerGabriel Hurley <gabehr@gmail.com>2010-10-25 20:50:53 +0000
commit9facaec719f3605c50d0188f95d979a692bdf8f9 (patch)
treee6495bf5eda5e3a55771c045e625ccf371499983 /docs
parent321e48f51bbc03af7315a4206f5ad6e6772f5aaf (diff)
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
Diffstat (limited to 'docs')
-rw-r--r--docs/howto/custom-template-tags.txt9
1 files changed, 8 insertions, 1 deletions
diff --git a/docs/howto/custom-template-tags.txt b/docs/howto/custom-template-tags.txt
index c4d2315bd4..95ce274460 100644
--- a/docs/howto/custom-template-tags.txt
+++ b/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