X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/3b0bf18d23d07d95c00a5e824d2f52cd98a1aae1..cf2b9630938e8c74f7037adacd2f5f0a4b6f2faa:/templatetags/containers.py diff --git a/templatetags/containers.py b/templatetags/containers.py index 490b56b..ca5e1e9 100644 --- a/templatetags/containers.py +++ b/templatetags/containers.py @@ -25,7 +25,7 @@ class ContainerNode(template.Node): self.nodelist_empty = template.NodeList() else: self.nodelist_empty = nodelist_empty - + def render(self, context): content = settings.TEMPLATE_STRING_IF_INVALID if 'page' in context: @@ -41,12 +41,18 @@ class ContainerNode(template.Node): if container_content: if self.as_var is None: self.as_var = self.name + + #make a new context context.push() context[self.as_var] = container_content - return nodelist_main.render(context) + nodelist = template.NodeList() + for node in self.nodelist_main: + nodelist.append(node.render(context)) + context.pop() + return nodelist.render(context) - if nodelist_empty is not None: - return nodelist_empty.render(context) + if self.nodelist_empty is not None: + return self.nodelist_empty.render(context) return '' @@ -72,6 +78,7 @@ class ContainerNode(template.Node): content = '' return content + def do_container(parser, token): """ {% container [[references ] as ] %} @@ -115,9 +122,11 @@ def do_container(parser, token): parser.delete_first_token() else: nodelist_empty = None - return BlockContainerNode(name, references, as_var, nodelist_main, nodelist_empty) + return ContainerNode(name, references, as_var, nodelist_main, nodelist_empty) else: # error raise template.TemplateSyntaxError('"%s" template tag provided without arguments (at least one required)' % tag) + + register.tag('container', do_container) register.tag('blockcontainer', do_container)