- page = context['page']
- if self.references:
- try:
- contentreference = page.contentreferences.get(name__exact=self.name, content_type=self.references)
- content = contentreference.content
- except ObjectDoesNotExist:
- pass
- else:
- try:
- contentlet = page.contentlets.get(name__exact=self.name)
- if contentlet.dynamic:
- try:
- 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)
- else:
- content = contentlet.content
- except ObjectDoesNotExist:
- pass
- if content and self.as_var:
- context[self.as_var] = content
- return ''
+ container_content = self.get_container_content(context)
+
+ if not self.nodelist_main:
+ if container_content and self.as_var:
+ context[self.as_var] = container_content
+ return ''
+ return container_content
+
+ 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
+ nodelist = template.NodeList()
+ for node in self.nodelist_main:
+ nodelist.append(node.render(context))
+ context.pop()
+ return nodelist.render(context)
+
+ if self.nodelist_empty is not None:
+ return self.nodelist_empty.render(context)
+
+ return ''
+
+ 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)
+ content = contentreference.content
+ except ObjectDoesNotExist:
+ content = ''
+ else:
+ try:
+ contentlet = page.contentlets.get(name__exact=self.name)
+ if contentlet.dynamic:
+ try:
+ 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))
+ else:
+ content = contentlet.content
+ except ObjectDoesNotExist:
+ content = ''