How can I create an invisible dummy page in Wagtail?
I need a "virtual" page object within Wagtail to build a menu for non Wagtail based pages and also external resources. (See my entry post here)
class MenuDummyPage(Page):
menu_description = models.CharField(max_length=255, blank=True)
menu_icon = models.CharField(max_length=255, blank=True)
menu_link = models.CharField(max_length=255, blank=True)
settings_panels = [
FieldPanel('menu_description'),
FieldPanel('menu_icon'),
FieldPanel('menu_link'),
]
def get_sitemap_urls(self):
return []
def serve(self, request):
pass
If I create the above page object then it is not listed within the generated wagtail sitemap.
But if I navigate on my own to that page manually the object is called. How can I stop this?
Example: If I create a MenuDummyPage with the title "This is a test" then the system will automatically generate a slug => "this-is-a-test".
If I call "/this-is-a-test"/ in my browser wagtail is answering because the slug exists. How can I remove this behavior for my "MenuDummyPage" objects?
If what you mean by a dummy page is a page under which other pages are kept in the page tree, then you could do the following:
The optional
link
field allows you to define a link if you wish for this position in the page tree structure. The above, again, assumes that you are using thisPage
-based item as a placeholder in thePage
tree so that you can have otherPage
s under it. As long as you don't render the url of this page in your template, then users should never know how to get to the url for theNode
, but if someone does get to the url for aNode
-type page, then thefirst_descendant
logic handles this situation by sending them to either the first descendant of theNode
or to the home page if no descendants ofNode
exist.In your template (note the use of
specific_class
):