Ticket #8088: include_tag.diff
File include_tag.diff, 1.8 KB (added by , 16 years ago) |
---|
-
django/template/loader_tags.py
1 from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable 1 from django.template import TemplateSyntaxError, TemplateDoesNotExist, VariableNode 2 2 from django.template import Library, Node, TextNode 3 3 from django.template.loader import get_template, get_template_from_string, find_template_source 4 4 from django.conf import settings … … 114 114 115 115 class IncludeNode(Node): 116 116 def __init__(self, template_name): 117 self.template_name = Variable (template_name)117 self.template_name = VariableNode(template_name) 118 118 119 119 def render(self, context): 120 120 try: 121 template_name = self.template_name.re solve(context)121 template_name = self.template_name.render(context) 122 122 t = get_template(template_name) 123 123 return t.render(context) 124 124 except TemplateSyntaxError, e: … … 178 178 Example:: 179 179 180 180 {% include "foo/some_include" %} 181 {% include var_template_name %} 182 {% include var_template_name|lower %} 181 183 """ 182 184 bits = token.contents.split() 183 185 if len(bits) != 2: 184 186 raise TemplateSyntaxError, "%r tag takes one argument: the name of the template to be included" % bits[0] 185 187 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]: 187 189 return ConstantIncludeNode(path[1:-1]) 188 return IncludeNode( bits[1])190 return IncludeNode(parser.compile_filter(bits[1])) 189 191 190 192 register.tag('block', do_block) 191 193 register.tag('extends', do_extends)