Ticket #8088: include_tag.diff

File include_tag.diff, 1.8 KB (added by David Avsajanishvili, 16 years ago)

"include" tag modified so, it can process template filters

  • django/template/loader_tags.py

     
    1 from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable
     1from django.template import TemplateSyntaxError, TemplateDoesNotExist, VariableNode
    22from django.template import Library, Node, TextNode
    33from django.template.loader import get_template, get_template_from_string, find_template_source
    44from django.conf import settings
     
    114114
    115115class IncludeNode(Node):
    116116    def __init__(self, template_name):
    117         self.template_name = Variable(template_name)
     117        self.template_name = VariableNode(template_name)
    118118
    119119    def render(self, context):
    120120        try:
    121             template_name = self.template_name.resolve(context)
     121            template_name = self.template_name.render(context)
    122122            t = get_template(template_name)
    123123            return t.render(context)
    124124        except TemplateSyntaxError, e:
     
    178178    Example::
    179179
    180180        {% include "foo/some_include" %}
     181        {% include var_template_name %}
     182        {% include var_template_name|lower %}
    181183    """
    182184    bits = token.contents.split()
    183185    if len(bits) != 2:
    184186        raise TemplateSyntaxError, "%r tag takes one argument: the name of the template to be included" % bits[0]
    185187    path = bits[1]
    186     if path[0] in ('"', "'") and path[-1] == path[0]:
     188    if path[0] in ('"', "'") and path[-1] == path[0] and not path[0] in path[1:-1]:
    187189        return ConstantIncludeNode(path[1:-1])
    188     return IncludeNode(bits[1])
     190    return IncludeNode(parser.compile_filter(bits[1]))
    189191
    190192register.tag('block', do_block)
    191193register.tag('extends', do_extends)
Back to Top