Django

Code

Ticket #1650: template-loader.diff

File template-loader.diff, 3.1 kB (added by clelland@gmail.com, 3 years ago)
  • django/template/loader_tags.py

    old new  
    5050            if self.parent_name_expr: 
    5151                error_msg += " Got this from the %r variable." % self.parent_name_expr #TODO nice repr. 
    5252            raise TemplateSyntaxError, error_msg 
     53        if hasattr(parent, 'render'): 
     54            return parent 
    5355        try: 
    5456            source, origin = find_template_source(parent, self.template_dirs) 
    5557        except TemplateDoesNotExist: 
     
    137139 
    138140    This tag may be used in two ways: ``{% extends "base" %}`` (with quotes) 
    139141    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). 
    142145    """ 
    143146    bits = token.contents.split() 
    144147    if len(bits) != 2: 
  • tests/othertests/templates.py

    old new  
    314314    # Three-level inheritance with {{ block.super }} from parent and grandparent 
    315315    'inheritance23': ("{% extends 'inheritance20' %}{% block first %}{{ block.super }}b{% endblock %}", {}, '1_ab3_'), 
    316316 
     317    # Inheritance from local context without use of template loader 
     318    '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'), 
     319 
     320    # Inheritance from local context with variable parent template 
     321    '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'), 
     322 
    317323    ### I18N ################################################################## 
    318324 
    319325    # {% spaceless %} tag 
  • docs/templates.txt

    old new  
    368368 
    369369This tag may be used in two ways: ``{% extends "base" %}`` (with quotes) uses 
    370370the literal value "base" as the name of the parent template to extend, or ``{% 
    371 extends variable %}`` uses the value of ``variable`` as the name of the parent 
    372 template to extend. 
     371extends variable %}`` uses the value of ``variable`` as either the name of the 
     372parent template to extend (if it evaluates to a string,) or as the parent 
     373tempate itelf (if it evaluates to a Template object). 
    373374 
     375 
    374376See `Template inheritance`_ for more information. 
    375377 
    376378filter