How do you access the menu model from a Zotonic template? -
i want write own style of menu, prefer in templates rather making own menu scomp.
i want able like:
{% if m.menu %} <ul> {% top_level_id in m.menu %} {% m.rsc[top_level_id] top_level %} <li><a href="{{ top_level.page_url }}">{{ top_level.title }}</a> {% if top_level.menu %} <ul> {% mid_level_id in top_level.menu %} {% m.rsc[mid_level_id] mid_level %} <li><a href="{{ midlevel.page_url }}">{{ mid_level.title }}</a></li> {% endwith %} {% endfor %} </ul> {% endif %} </li> {% endwith %} {% endfor %} </ul> {% endif %}
how access menu model zotonic template?
to add previous answer. standard _menu.tpl
receives list menu items. list result of depth-first tree walk of complete menu. every menu record with
{menurscid, depthofmenu, nrinsubmenu, hassubmenuflag}
where top level menu has depth of 1 , first menu item in menu has nr of 1.
all menu items current user not allowed see filtered out.
the code of default template:
<ul id="{{ id_prefix }}navigation" class="clearfix at-menu do_superfish"> {% mid,depth,nr,has_sub in menu %} {% if not mid %}{% if depth > 1 %}</ul></li>{% endif %} {% else %} {% if nr == 1 , not forloop.first %}<ul{% if mid|member:path %} class="onpath"{% endif %}>{% endif %} <li id="{{ id_prefix }}nav-item-{{nr}}" class="{% if is_first %}first {% endif %}{% if is_last %}last{% endif %}"> <a href="{{ m.rsc[mid].page_url }}" class="{{ m.rsc[mid].name }}{% if mid == id %} current{% else %}{% if mid|member:path %} onpath{% endif %}{% endif %}">{{ m.rsc[mid].short_title|default:m.rsc[mid].title }}</a> {% if not has_sub %}</li>{% endif %} {% endif %} {% endfor %} {% if forloop.last %}{% include "_menu_extra.tpl" %}{% endif %} </ul>
Comments
Post a Comment