Django models 如何在Wagtail中为侧菜单生成部分中的页面列表?

Django models 如何在Wagtail中为侧菜单生成部分中的页面列表?,django-models,django-templates,wagtail,Django Models,Django Templates,Wagtail,我是一个真正的摇摆舞初学者。如何在Wagtail中为侧菜单生成部分中的页面列表 例如,我有以下网站结构: home/ fruits/ apples/ oranges/ grapes/ vegetables/ kale/ spinach/ cabbage/ home是使用home\u page.html模板的HomePage类型,所有子页面都是使用content\u page.html

我是一个真正的摇摆舞初学者。如何在Wagtail中为侧菜单生成部分中的页面列表

例如,我有以下网站结构:

home/
    fruits/
        apples/
        oranges/
        grapes/
    vegetables/
        kale/
        spinach/
        cabbage/
home
是使用
home\u page.html
模板的
HomePage
类型,所有子页面都是使用
content\u page.html
模板的
ContentPage
类型

我想为所有内容页面制作一个侧菜单,列出它们组中的所有页面。例如,此列表:

Fruits
Apples
Oranges
Grapes
应该是
水果
苹果
橙子
葡萄
页面的侧菜单

page.get_children
在模板中仅列出页面是否有子项,因此,在本例中,只列出水果和蔬菜

我该怎么做那副菜单呢

Wagtail文档中的示例似乎暗示我不能只使用像
ContentPage
这样的通用内容类型来获得我想要的那种列表,这是真的吗

非常感谢

欢迎来到Wagtail

与web开发中的大多数事情一样,有几种方法可以做到这一点。在刚开始的时候,最简单的理解就是通过模板完成这一切。因此,在您的
主页.html
中,您可以:

{% for parent in page.get_children %}
    Page title: {{ parent.title }} <br />

    {% if parent.get_children.count %}
        {% for child in parent.get_children %}
            - Child page title: {{ child.title }}<br/>
        {% endfor %}
    {% endif %}
{% endfor %}
在你的模板中,你会写:

    {% for child_page in home_page.get_children %}
        Page title: {{ child_page.title }} <br />

        {% if child_page.get_children.count %}
            {% for grandchild_page in child_page.get_children %}
                - Child page title: {{ grandchild_page.title }}<br/>
            {% endfor %}
        {% endif %}
    {% endfor %}
<!-- On `/fruits/` this will be the Home Page title. On `/fruits/apples/` this will be the Fruits page title. -->
<h2>{{ self.get_parent.title }}<h2>

{% for sibling in self.get_siblings %}
   <a href="{{ sibling.url }}">{{ sibling.title }}</a>
{% endfor %}