I am trying to include a page editable through the mezzanine admin in all the pages on my site. I read through the Mezzanine doc and the source and cannot figure out how to do this.
From the docs, I thought I could pass my page as an extra context, something like:
mezzanine.pages.views.page(request, slug, template=u'pages/page.html', extra_context={'mypage':<get_page_by_its_slug>})
But the doc says that the extra context is a mezzanine.pages.middleware.PageMiddleware object, which sets the slug from the request.
Do I need to write a context processor to do this? How do a load a specific page by its slug?
Just in case this helps someone out there, I created a context processor to solve this:
# context_processors.py
from mezzanine.pages.models import Page
def featured(request):
# editable page, get by ID or slug or title...
featured_page = Page.objects.get(id=49)
return {'featured_page': featured_page}
added the context processor into my settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
## ...etc...,
"myapp.context_processors.featured",
)
and included the featured content in the base.html template:
{% block right_panel %}
<div>
{% editable featured_page.richtextpage.content %}
{{ featured_page.richtextpage.content|richtext_filter|safe }}
{% endeditable %}
</div>
{% endblock %}
If you know of a simpler way to do this, I'd love to hear your solution!
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