I don't found proper way to update Wagtail CMS Page context.
For instance i have my homepage model:
class HomePage(Page):
about = RichTextField(blank=True)
date = models.DateField(auto_now=True)
content_panels = Page.content_panels + [
FieldPanel('about', classname="full")
]
class Meta:
verbose_name = "Homepage"
And I also want some third part information to be included on that page. In my case its forum. It will be great to write some ViewMixin, like:
class ForumMixin(object):
pass
# add latest forums to context
I can do it by writing my Django CBV, but i really want to know Wagtail Native Way. Thanks!
You can do this by overriding the get_context
method on your page model:
class HomePage(Page):
def get_context(self, request):
context = super(HomePage, self).get_context(request)
context['forums'] = Forum.objects.all()
return context
This makes the variable forums
available on your template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With