from django import template from django.conf import settings from django.template import Library, Node, TemplateSyntaxError from settings import PROJECT_ROOT import yaml from os.path import join register = Library() @register.simple_tag def navlist(): '''Generates a navigation list from a yaml file with syntax: Heading1: - name: A link href: /alink - name: Another link href: /anotherlink Heading2: - name: A link href: /alink - name: Another link href: /anotherlink ''' out = [] tree = yaml.load(open(join(PROJECT_ROOT, 'menu.yaml')).read()) for section in tree.keys(): out.append('''\