Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1650: the {% extends %} tag now can extend a Template object p…

…assed into the context. Thanks, clelland@gmail.com.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3465 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 847b1ed54ec9da078a2524a3791057f024839eee 1 parent 6537401
Jacob Kaplan-Moss authored July 27, 2006
7  django/template/loader_tags.py
@@ -50,6 +50,8 @@ def get_parent(self, context):
50 50
             if self.parent_name_expr:
51 51
                 error_msg += " Got this from the %r variable." % self.parent_name_expr #TODO nice repr.
52 52
             raise TemplateSyntaxError, error_msg
  53
+        if hasattr(parent, 'render'):
  54
+            return parent
53 55
         try:
54 56
             source, origin = find_template_source(parent, self.template_dirs)
55 57
         except TemplateDoesNotExist:
@@ -137,8 +139,9 @@ def do_extends(parser, token):
137 139
 
138 140
     This tag may be used in two ways: ``{% extends "base" %}`` (with quotes)
139 141
     uses the literal value "base" as the name of the parent template to extend,
140  
-    or ``{% extends variable %}`` uses the value of ``variable`` as the name
141  
-    of the parent template to extend.
  142
+    or ``{% extends variable %}`` uses the value of ``variable`` as either the
  143
+    name of the parent template to extend (if it evaluates to a string,) or as
  144
+    the parent tempate itelf (if it evaluates to a Template object).
142 145
     """
143 146
     bits = token.contents.split()
144 147
     if len(bits) != 2:
12  docs/templates.txt
@@ -363,10 +363,14 @@ extends
363 363
 
364 364
 Signal that this template extends a parent template.
365 365
 
366  
-This tag may be used in two ways: ``{% extends "base.html" %}`` (with quotes)
367  
-uses the literal value "base.html" as the name of the parent template to
368  
-extend, or ``{% extends variable %}`` uses the value of ``variable`` as the
369  
-name of the parent template to extend.
  366
+This tag may be used in two ways: 
  367
+
  368
+   * ``{% extends "base.html" %}`` (with quotes) uses the literal value
  369
+     "base.html" as the name of the parent template to extend
  370
+
  371
+   * ``{% extends variable %}`` uses the value of ``variable`` as either the
  372
+     name of the parent template to extend (if it evaluates to a string,) or
  373
+     as the parent tempate itelf (if it evaluates to a Template object).
370 374
 
371 375
 See `Template inheritance`_ for more information.
372 376
 
6  tests/othertests/templates.py
@@ -410,6 +410,12 @@ def method(self):
410 410
     # Three-level inheritance with {{ block.super }} from parent and grandparent
411 411
     'inheritance23': ("{% extends 'inheritance20' %}{% block first %}{{ block.super }}b{% endblock %}", {}, '1_ab3_'),
412 412
 
  413
+    # Inheritance from local context without use of template loader
  414
+    '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'),
  415
+
  416
+    # Inheritance from local context with variable parent template
  417
+    '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'),
  418
+
413 419
     ### I18N ##################################################################
414 420
 
415 421
     # {% spaceless %} tag

0 notes on commit 847b1ed

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