如何在w中添加多级菜单支持(支持基于非wa的页面) [英] How to add multi-level menu support to wagtail (with support for non-wagtail based pages)
问题描述
如何添加对自定义菜单的支持,这些菜单也可用于非基于Wagtail的页面.
How can I add support for custom menus which will work also with non-Wagtail based pages.
- 例如,通过直接向注册页面提供相对网址,例如"/account/registration")
- 例如,通过直接向外部网页(例如"www.stackoverflow.com")提供绝对网址
我发现了一个非常有趣的项目:https://github.com/rkhleics/wagtailmenus
不幸的是在主菜单中不支持子菜单.
I found this very interesting project: https://github.com/rkhleics/wagtailmenus
Unfortunately is does not support submenus in the main menu.
推荐答案
关于Wagtail的一件事是,我所说的数据树仅由页面组成(称为
One thing about Wagtail is that what I would call the data tree is made up only of pages (it's called a page tree). This tree is used as the basis for navigation but, of course, sometimes you might want a navigation item in this tree to be something other than a page. I accomplish what you want to do by subclassing Page
:
from django.http import HttpResponseRedirect
class Node(Page):
subpage_types = [your subpage types]
parent_page_types = [your parent page types]
link = models.CharField(max_length=255, default='', blank='True')
content_panels = Page.content_panels + [
FieldPanel('link')
]
def serve(self, request):
if self.link is not None:
return HttpResponseRedirect(self.link)
else:
pass
在模板中:
{% for item in menu_items %}
<li>
<a href="{% if item.specific.link and item.specific.link != '' %}{{ item.specific.link }}{% else %}{% pageurl item %}{% endif %}">{{ item.title }
</a>
</li>
{% endfor %}
这篇关于如何在w中添加多级菜单支持(支持基于非wa的页面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!