from django.template import Library, Node, TemplateSyntaxError register = Library() def do_menubox(parser, token): nodelist = parser.parse(('endmenubox',)) parser.delete_first_token() try: tag_name, title = token.split_contents() except ValueError: raise TemplateSyntaxError, "%r tag requires exactly two arguments" % \ token.contents.split()[0] return MenuboxNode(nodelist, parser.compile_filter(title)) class MenuboxNode(Node): def __init__(self, nodelist, title): self.nodelist = nodelist self.title = title def render(self, context): title = self.title.resolve(context) output = self.nodelist.render(context) return '''

%s

%s
''' % (title, output) register.tag('menubox', do_menubox)