Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
template tag for django-cms menus that roots at a given menu level
from menus.menu_pool import menu_pool
from django import template
from menus.templatetags.menu_tags import cut_after
register = template.Library()
@register.inclusion_tag('cms/dummy.html', takes_context=True)
def show_rooted_sub_menu(context, levels=100, root_level=0, template="menu/sub_menu.html"):
show the sub menu of the current nav-node.
-levels: how many levels deep
-temlplate: template used to render the navigation
# If there's an exception (500), default context_processors may not be called.
request = context['request']
except KeyError:
return {'template': 'menu/empty.html'}
nodes = menu_pool.get_nodes(request)
children = []
for node in nodes:
if (node.ancestor and node.level == root_level) or (node.selected and node.level == root_level):
cut_after(node, levels, [])
children = node.children
for child in children:
child.parent = None
children = menu_pool.apply_modifiers(children, request, post_cut=True)
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment