from django import template
from feincms.models import Page
from feincms.templatetags.utils import *

register = template.Library()


class NavigationNode(SimpleAssignmentNodeWithVarAndArgs):
    """
    Example:
    {% feincms_navigation of page as sublevel level=2 %}
    {% for p in sublevel %}
        <a href="{{ p.get_absolute_url }}">{{ p.title }}</a>
    {% endfor %}
    """

    def what(self, instance, args):
        level = int(args.get('level', 1))

        if level <= 1:
            return Page.objects.toplevel_navigation()

        if instance.level+2 == level:
            return instance.children.in_navigation()

        try:
            return instance.get_ancestors()[level-2].children.in_navigation()
        except IndexError:
            return []
register.tag('feincms_navigation', do_simple_assignment_node_with_var_and_args_helper(NavigationNode))




@@ -871,10 +871,423 @@
 Node))%0A%0A
+%0Aclass ParentLinkNode(SimpleNodeWithVarAndArgs):%0A%09def what(self, page, args):%0A%09%09level = int(args.get('level', 1))%0A%0A%09%09if page.level+1 == level:%0A%09%09%09return page.get_absolute_url()%0A%09%09elif page.level+1 %3C level:%0A%09%09%09return '#'%0A%0A%09%09try:%0A%09%09%09return page.get_ancestors()%5Blevel-1%5D.get_absolute_url()%0A%09%09except IndexError:%0A%09%09%09return '#'%0Aregister.tag('feincms_parentlink', do_simple_node_with_var_and_args_helper(ParentLinkNode))
 %0A%0A

Add feincms_parentlink template tag