如何从 Zotonic 模板访问菜单模型?
我想编写自己风格的菜单,但我更喜欢在模板中完成,而不是制作自己的菜单 scomp。
我基本上希望能够执行以下操作:
{% if m.menu %}
<ul>
{% for top_level_id in m.menu %}
{% with m.rsc[top_level_id] as top_level %}
<li><a href="{{ top_level.page_url }}">{{ top_level.title }}</a>
{% if top_level.menu %}
<ul>
{% for mid_level_id in top_level.menu %}
{% with m.rsc[mid_level_id] as mid_level %}
<li><a href="{{ midlevel.page_url }}">{{ mid_level.title }}</a></li>
{% endwith %}
{% endfor %}
</ul>
{% endif %}
</li>
{% endwith %}
{% endfor %}
</ul>
{% endif %}
如何从 Zotonic 模板访问菜单模型?
I want to write my own style of menu, but I would prefer to do it in the templates rather than making my own menu scomp.
I basically want to be able to do something like:
{% if m.menu %}
<ul>
{% for top_level_id in m.menu %}
{% with m.rsc[top_level_id] as top_level %}
<li><a href="{{ top_level.page_url }}">{{ top_level.title }}</a>
{% if top_level.menu %}
<ul>
{% for mid_level_id in top_level.menu %}
{% with m.rsc[mid_level_id] as mid_level %}
<li><a href="{{ midlevel.page_url }}">{{ mid_level.title }}</a></li>
{% endwith %}
{% endfor %}
</ul>
{% endif %}
</li>
{% endwith %}
{% endfor %}
</ul>
{% endif %}
How do you access the menu model from a Zotonic template?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加到我之前的答案。标准
_menu.tpl
接收包含所有菜单项的列表。该列表是完整菜单的深度优先树形遍历的结果。每个菜单都是一条记录,其中顶级菜单的深度为1,菜单中的第一个菜单项的nr为1。
所有不允许当前用户看到的菜单项都会被过滤掉。
默认模板的代码:
To add to my previous answer. The standard
_menu.tpl
receives a list with all menu items. This list is the result of a depth-first tree walk of the complete menu. Every menu is a record withWhere the top level menu has a depth of 1 and the first menu item in a menu has a nr of 1.
All menu items that the current user is not allowed to see are filtered out.
The code of the default template:
(即将推出的)0.5 版本和 Zotonic 的提示使用模板来显示菜单。检查
mod_menu/templates/_menu.tpl
。该模板由菜单 scomp 调用。
The (upcoming) 0.5-release and tip of Zotonic use a template to display the menu. Check
mod_menu/templates/_menu.tpl
.This template is called by the menu scomp.