Made referencing containers optional on pages. Fixes a bug.
[philo.git] / templatetags / containers.py
index 25156f2..2e40e53 100644 (file)
@@ -25,11 +25,11 @@ 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:
-                       container_content = self.get_container_content(context['page'])
+                       container_content = self.get_container_content(context)
                
                if self.nodelist_main is None:
                        self.nodelist_main
@@ -56,7 +56,8 @@ class ContainerNode(template.Node):
                
                return ''
        
-       def get_container_content(self, page):
+       def get_container_content(self, context):
+               page = context['page']
                if self.references:
                        try:
                                contentreference = page.contentreferences.get(name__exact=self.name, content_type=self.references)
@@ -71,13 +72,14 @@ class ContainerNode(template.Node):
                                                content = mark_safe(template.Template(contentlet.content, name=contentlet.name).render(context))
                                        except template.TemplateSyntaxError, error:
                                                if settings.DEBUG:
-                                                       content = ('[Error parsing contentlet \'%s\': %s]' % self.name, error)
+                                                       content = ('[Error parsing contentlet \'%s\': %s]' % (self.name, error))
                                else:
                                        content = contentlet.content
                        except ObjectDoesNotExist:
                                content = ''
                return content
 
+
 def do_container(parser, token):
        """
        {% container <name> [[references <type>] as <variable>] %} 
@@ -125,5 +127,7 @@ def do_container(parser, token):
                
        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)