summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2006-07-27 23:23:55 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2006-07-27 23:23:55 +0000
commit847b1ed54ec9da078a2524a3791057f024839eee (patch)
tree912b5931a45d3582b383aa9da2b09d2983efc90b
parent6537401ca45dcaeb8eb285bcf451e403f538eb93 (diff)
Fixed #1650: the {% extends %} tag now can extend a Template object passed into the context. Thanks, clelland@gmail.com.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3465 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/loader_tags.py7
-rw-r--r--docs/templates.txt12
-rw-r--r--tests/othertests/templates.py6
3 files changed, 19 insertions, 6 deletions
diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
index f847ea123f..7f22f207b6 100644
--- a/django/template/loader_tags.py
+++ b/django/template/loader_tags.py
@@ -50,6 +50,8 @@ class ExtendsNode(Node):
if self.parent_name_expr:
error_msg += " Got this from the %r variable." % self.parent_name_expr #TODO nice repr.
raise TemplateSyntaxError, error_msg
+ if hasattr(parent, 'render'):
+ return parent
try:
source, origin = find_template_source(parent, self.template_dirs)
except TemplateDoesNotExist:
@@ -137,8 +139,9 @@ def do_extends(parser, token):
This tag may be used in two ways: ``{% extends "base" %}`` (with quotes)
uses the literal value "base" as the name of the parent template to extend,
- or ``{% extends variable %}`` uses the value of ``variable`` as the name
- of the parent template to extend.
+ or ``{% extends variable %}`` uses the value of ``variable`` as either the
+ name of the parent template to extend (if it evaluates to a string,) or as
+ the parent tempate itelf (if it evaluates to a Template object).
"""
bits = token.contents.split()
if len(bits) != 2:
diff --git a/docs/templates.txt b/docs/templates.txt
index 6117bf7b84..d33575f7fd 100644
--- a/docs/templates.txt
+++ b/docs/templates.txt
@@ -363,10 +363,14 @@ extends
Signal that this template extends a parent template.
-This tag may be used in two ways: ``{% extends "base.html" %}`` (with quotes)
-uses the literal value "base.html" as the name of the parent template to
-extend, or ``{% extends variable %}`` uses the value of ``variable`` as the
-name of the parent template to extend.
+This tag may be used in two ways:
+
+ * ``{% extends "base.html" %}`` (with quotes) uses the literal value
+ "base.html" as the name of the parent template to extend
+
+ * ``{% extends variable %}`` uses the value of ``variable`` as either the
+ name of the parent template to extend (if it evaluates to a string,) or
+ as the parent tempate itelf (if it evaluates to a Template object).
See `Template inheritance`_ for more information.
diff --git a/tests/othertests/templates.py b/tests/othertests/templates.py
index 3d23d8123b..9975f3b05c 100644
--- a/tests/othertests/templates.py
+++ b/tests/othertests/templates.py
@@ -410,6 +410,12 @@ TEMPLATE_TESTS = {
# Three-level inheritance with {{ block.super }} from parent and grandparent
'inheritance23': ("{% extends 'inheritance20' %}{% block first %}{{ block.super }}b{% endblock %}", {}, '1_ab3_'),
+ # Inheritance from local context without use of template loader
+ 'inheritance24': ("{% extends context_template %}{% block first %}2{% endblock %}{% block second %}4{% endblock %}", {'context_template': template.Template("1{% block first %}_{% endblock %}3{% block second %}_{% endblock %}")}, '1234'),
+
+ # Inheritance from local context with variable parent template
+ 'inheritance25': ("{% extends context_template.1 %}{% block first %}2{% endblock %}{% block second %}4{% endblock %}", {'context_template': [template.Template("Wrong"), template.Template("1{% block first %}_{% endblock %}3{% block second %}_{% endblock %}")]}, '1234'),
+
### I18N ##################################################################
# {% spaceless %} tag