szm
szm

Reputation: 95

How to import a Wagtail page on all the other wagtail pages

I want to add some content on one of my Wagtail pages and I am trying to import that Wagtail page on all my other wagtail pages. The reason I am trying to do this is that if in the future I make a change on the content it should consistently reflect on all the other Wagtail pages. Is there a way that I can import a Wagtail page on all my other Wagtail pages, if so please let me know. Thanks in advance!

I have a website which has the following Configurations: 1) Django-2.0.8 2) Wagtail-2.2.4

Upvotes: 1

Views: 729

Answers (1)

gasman
gasman

Reputation: 25237

A custom template tag is a good way to achieve this, as it provides a place to run custom Python code (for retrieving the necessary data) before outputting the results to the template, either directly as a string or by rendering a template. For example, if you had a footer_text field on a HomePage model, and wanted to display the footer text of the HomePage with slug 'home' on every page, you could define a custom tag as follows:

@register.inclusion_tag('myapp/includes/footer.html')
def footer():
    homepage = HomePage.objects.get(slug='home')
    return {'footer_text': homepage.footer_text}

You could also look at Wagtail's site settings module as a way to define global content to be re-used across a site (although it's missing a few features that you'd get from defining it on a page model, such as moderation workflow and revision history).

Upvotes: 5

Related Questions