Skip to content

Instantly share code, notes, and snippets.

@mkoistinen
Created November 19, 2014 15:26
Show Gist options
  • Save mkoistinen/a887098974702041bc9c to your computer and use it in GitHub Desktop.
Save mkoistinen/a887098974702041bc9c to your computer and use it in GitHub Desktop.
This is like render_model_block but for plugins!
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import template
from classytags.core import Tag, Options
from classytags.arguments import Argument
register = template.Library()
class RenderPluginBlock(Tag):
"""
Acts like the CMS's templatetag 'render_model_block' but with a plugin
instead of a model. This is used to link from a block of markup to a
plugin's changeform.
"""
name = 'render_plugin_block'
options = Options(
Argument('plugin'),
blocks=[('endrender_plugin_block', 'nodelist')],
)
def render_tag(self, context, plugin, nodelist):
context.push()
context['inner'] = nodelist.render(context)
context['plugin'] = plugin
t = template.Template('{% load l10n %}<div class="cms_plugin cms_plugin-{{ plugin.id|unlocalize }}">{{ inner }}</div>')
output = t.render(context)
context.pop()
return output
register.tag(RenderPluginBlock)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment