I am building my third Wagtail CMS site (v.1.8) but have never been able to figure out the slugurl
& pageurl
tags to create internal links and have just hardcoded all the links, even though hardcoding goes against the grain in my workflow. Can someone please help me out. And yes, I did add {% load wagtailcore_tags %}
to my page.
For demonstration purposes, I am going to use a very simple model that is going to give my client a template with just a title and a body as one of their page templates. The page is aptly called StandardPage(Page)
and a template named standard_page.html
. I created an about
page and want to provide a link to the page in my header and footer. I know I can hardcode it; but that is not what I would to do.
I have tried {% slugurl page.about %}
but link returns None
- I even tried {% slugurl standardpage.about %}
thinking I was missing something but of course it returns None
as well.
I always used named routes in all my Django projects and not being able to figure this out is driving me crazy.
Here is my model for reference. Thank you.
class StandardPage(Page):
body = RichTextField(blank=True)
search_fields = Page.search_fields + [
index.SearchField('title'),
index.SearchField('body'),
]
class Meta:
verbose_name = 'Standard Page - No Image Placement'
content_panels = Page.content_panels + [
FieldPanel('body', classname="full"),
]
{% slugurl page.about %}
would look for a field calledabout
on your current page - this fails because there's no field with that name.If you want to link to the page with the slug 'about', use
{% slugurl 'about' %}
. (However, you should realise that this really isn't much different from hard-coding the URL... if you're worried about hard-coding because an editor might accidentally rename the page and break the link, thenslugurl
won't protect you against that. Ultimately you have to trust your editors not to do anything silly!)