【问题标题】:Menu pages in Mezzanine夹层中的菜单页面
【发布时间】:2015-07-01 16:05:57
【问题描述】:

在 Mezzanine / Django 中,我有几个嵌套页面,但只有嵌套最深的页面有内容。对于每个中间页面,我只想显示其直接子级的菜单。例如,给定布局:

Chapter 1
    Section 1.1
        Subsection 1.1.1
        Subsection 1.1.2
    Section 1.2
        Subsection 1.2.1
Chapter 2
    Section 2.1
        Subsection 2.1.1

作为chapter-1 的页面应该只显示一个列表

* Section 1.1
* Section 1.2

我可以通过为包含以下内容的每个章节创建自定义模板来做到这一点:

{% load pages_tags %}
{% page_menu "pages/menus/chapter_menu.html" %}

chapter_menu.html 是我的菜单模板:

{% load pages_tags %}
<ul>
{% for page in page_branch %}
{% if page.in_menu %}
{% if page.is_current_child %}
<li>
    <a href="{{ page.get_absolute_url }}">{{ page.title }}</a>
</li>
{% else %}
{% page_menu page %}
{% endif %}
{% endif %}
{% endfor %}
</ul>

但是,每个模板名称(例如 pages/chapter-1.html)都必须与它所引用的页面的 slug 匹配,因此我需要为每个章节和每个章节复制这些模板。

不重复模板的正确方法是什么?

【问题讨论】:

    标签: python django content-management-system mezzanine


    【解决方案1】:

    我认为您不需要为每个菜单创建模板。我通过使用 enter link description here 中的 tree.html 和 my_menu.html 解决了这个问题

    所以我只是将 menus/tree.html 替换为:

    {% load i18n future pages_tags %}
    {% spaceless %}
    {% page_menu "pages/menus/my_menu.html" %}
    {% endspaceless %}
    

    并添加了 menus/my_menu.html:

    {% load pages_tags %}
    {% for page in page_branch %}
        {% if page.is_current_child %}
        <a href="{{ page.get_absolute_url }}">{{ page.title }}</a>
        {% endif %}
        {% if page.is_current_or_ascendant %}
            {% if page.has_children_in_menu %}{% page_menu page %}{% endif %}
        {% endif %}
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 2013-07-18
      • 2015-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-18
      • 1970-01-01
      相关资源
      最近更新 更多