[Django]-Django CMS plugin context vs. page context

5👍

How about something like this..

In your cms_plugins.py

If you want the current_page:

def render(self, context, instance, placeholder):
    context = super(CrossItemsPlugin, self).render(context, instance, placeholder)
    request = context['request']
    page = request.current_page

   # your logic goes here

If you want the current ‘article’… you’ll need to set it in your views.py

def get_context_data(self, **kwargs):
    context = super(NewsDetailView, self).get_context_data(**kwargs)
    setattr(self.request, 'current_article', self.object)
    return context

And you could access that in the plugin render method.

def render(self, context, instance, placeholder):
    context = super(CrossItemsPlugin, self).render(context, instance, placeholder)
    request = context['request']
    article = request.current_article

Leave a comment