Code

Ticket #8088: include_tag.diff

File include_tag.diff, 1.8 KB (added by avsd, 6 years ago)

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

Line 
1Index: django/template/loader_tags.py
2===================================================================
3--- django/template/loader_tags.py      (revision 8194)
4+++ django/template/loader_tags.py      (working copy)
5@@ -1,4 +1,4 @@
6-from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable
7+from django.template import TemplateSyntaxError, TemplateDoesNotExist, VariableNode
8 from django.template import Library, Node, TextNode
9 from django.template.loader import get_template, get_template_from_string, find_template_source
10 from django.conf import settings
11@@ -114,11 +114,11 @@
12 
13 class IncludeNode(Node):
14     def __init__(self, template_name):
15-        self.template_name = Variable(template_name)
16+        self.template_name = VariableNode(template_name)
17 
18     def render(self, context):
19         try:
20-            template_name = self.template_name.resolve(context)
21+            template_name = self.template_name.render(context)
22             t = get_template(template_name)
23             return t.render(context)
24         except TemplateSyntaxError, e:
25@@ -178,14 +178,16 @@
26     Example::
27 
28         {% include "foo/some_include" %}
29+        {% include var_template_name %}
30+        {% include var_template_name|lower %}
31     """
32     bits = token.contents.split()
33     if len(bits) != 2:
34         raise TemplateSyntaxError, "%r tag takes one argument: the name of the template to be included" % bits[0]
35     path = bits[1]
36-    if path[0] in ('"', "'") and path[-1] == path[0]:
37+    if path[0] in ('"', "'") and path[-1] == path[0] and not path[0] in path[1:-1]:
38         return ConstantIncludeNode(path[1:-1])
39-    return IncludeNode(bits[1])
40+    return IncludeNode(parser.compile_filter(bits[1]))
41 
42 register.tag('block', do_block)
43 register.tag('extends', do_extends)