如何从 Zotonic 模板访问菜单模型?

发布于 2024-09-25 14:40:42 字数 746 浏览 0 评论 0原文

我想编写自己风格的菜单,但我更喜欢在模板中完成,而不是制作自己的菜单 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坏尐絯℡ 2024-10-02 14:40:42

添加到我之前的答案。标准_menu.tpl接收包含所有菜单项的列表。该列表是完整菜单的深度优先树形遍历的结果。每个菜单都是一条记录,

{MenuRscId, DepthOfMenu, NrInSubMenu, HasSubMenuFlag}

其中顶级菜单的深度为1,菜单中的第一个菜单项的nr为1。

所有不允许当前用户看到的菜单项都会被过滤掉。

默认模板的代码:

<ul id="{{ id_prefix }}navigation" class="clearfix at-menu do_superfish">
{% for mid,depth,nr,has_sub in menu %}
  {% if not mid %}{% if depth > 1 %}</ul></li>{% endif %}
  {% else %}
     {% if nr == 1 and 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>

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 with

{MenuRscId, DepthOfMenu, NrInSubMenu, HasSubMenuFlag}

Where 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:

<ul id="{{ id_prefix }}navigation" class="clearfix at-menu do_superfish">
{% for mid,depth,nr,has_sub in menu %}
  {% if not mid %}{% if depth > 1 %}</ul></li>{% endif %}
  {% else %}
     {% if nr == 1 and 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>
寻梦旅人 2024-10-02 14:40:42

(即将推出的)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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文