def list_menu(context, position_id): """ Simple and generic menu tags to print menu items as a html list. example: {% list_menu 'top_menu' %} """ request = context.get('request') title, items = get_menu_by_position(position_id) menu_tag, menu_class, before_link, after_link = get_menu_components( position_id) output = [] output.append('<%s class="ul_toplevel %s">' % (menu_tag, menu_class)) top_menu_count = count_menu_children(items, 0) counter = 0 for menu in items: if menu['parent_id'] == 0: current_class = '' if request.path == menu.get('url'): current_class = 'current' if counter == 0: output.append('<li class="li_toplevel first menu_%s %s">' % (menu['id'], current_class)) elif counter == top_menu_count - 1: output.append('<li class="li_toplevel last menu_%s %s">' % (menu['id'], current_class)) else: output.append('<li class="li_toplevel menu_%s %s">' % (menu['id'], current_class)) output.append('%s<a href="%s" title="%s">%s</a>%s' % (before_link, menu['url'], menu['title'], menu['title'], after_link)) output.append(render_menu_children(request, menu, items, menu_tag)) output.append('</li>') counter += 1 output.append('</%s>' % menu_tag) return u'\n'.join(output)
def render(self, context): title, items = get_menu_by_position(self.position_id) context[self.varname + '_title'] = title context[self.varname] = items return ''