Search code examples
djangodjango-cmsfeincms

django-cms getting the page context in an application hook


Consider this cms_app.py

from django.utils.translation import ugettext_lazy as _
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool


class FooHook(CMSApp):
    name = _("FooHook Plugin")
    urls = ["foo.urls"]

apphook_pool.register(FooHook)

The foo app, has a views model which contains to default django views, ListView and DetailView.. These have their default templates, inheriting from a base.html, these are foo_list.html and foo_detail.html..

The documentation is completely unclear how to get, for example the cms page's sidebar content or page context variable at all, within those templates..

Feincms has the {% fragment %} template tag for this purpose, how can one achieve this in django-cms?


Solution

  • To access the page you can use {{ request.current_page }} To use the plugin system in your templates use {% static_placeholder my_name %} instead of the {% placeholder %} tags.

    It is always preferable to use the static_placeholders in apphooks as you do not know what template and what placeholders the page actually has.