Reputation: 59
I have a site that is mostly made with Django but has a few content pages that need to be managed by Wagtail.
How can I link to the pages created with Wagtail in Django templates? I don't want to have to hardcode any of the pages. The client should be able to make a page in Wagtail and a link should be created to that page in Django templates.
The problem is that I don't know how to reference Wagtail pages through Django templates.
Upvotes: 0
Views: 976
Reputation: 3108
When you say
reference Wagtail pages through Django templates
I assume you mean render the navigation that will take the user to a page if they click on a navigation item. To render the navigation for the page tree, in the a template file (typically base.html
) you could do:
{% for item in request.site.root_page.get_children.live.in_menu %}
<a href="{% pageurl item %}">{{ item.title }}</a>
{% endfor %}
The above is the simplest rendering of page navigation. There are a number of other considerations you will likely run into when building navigation, one of which is building nested navigation. I could also post about this if you need that information (I build unlimited nested navigation through a recursive call to a small fragment of html in a separate file from base.html
).
Upvotes: 2