一致的 Wagtail 菜单显示 parents、children 和兄弟姐妹

Consistent Wagtail menus showing parents, children and siblings

我有一个简单的 Wagtail 网站,由几个类型为 HomePage 的页面组成 我想对从 创建的所有页面使用 Wagtails in-built 菜单系统主页 模型和home_page.html 模板。所有页面都选择了在菜单中显示:

使用本指南 here,我创建了以下 get_context 方法:

class HomePage(Page, Dreamer, Seo):

    def get_context(self, request):
        context = super(HomePage, self).get_context(request)
        context['menuitems'] = self.get_children().filter(live=True, show_in_menus=True)

... 并将以下代码放入我的模板中:

{% for menu in menuitems   %}
    <a class="nav-item nav-link active" href="{{menu.url}}">{{menu.title}}</a>
{% endfor %}

除了根本不显示根主页外,菜单显示 child 页面,直到我跟随 link 到 child 页面时,所有 links消失了(因为页面不再是children)。

问题:即使我在同级 parent 或 child 页面上,如何让菜单显示根主页和 child 页面?

非常感谢任何帮助。

变化:

context['menuitems'] = self.get_children().filter(live=True, show_in_menus=True)

至:

context['menuitems'] = request.site.root_page.get_descendants(inclusive=True).live().in_menu()