def render(request, template, context=None, error_page=False): context = context or {} navigation = site.visible_branches(request) sections = navigation[0] try: actions = navigation[1] except IndexError: actions = [] try: pages = navigation[2] except IndexError: pages = [] context.update({'sections': sections, 'actions': actions, 'pages': pages}) if error_page: # admittedly haxy solution for displaying navs on error pages context['actions'] = [] context['pages'] = [] for item in navigation[0]: item['is_active'] = False else: context['active_link'] = None for item in navigation[-1]: if item['is_active']: context['active_link'] = item break return dj_render(request, template, context)