Created
November 19, 2014 15:26
-
-
Save mkoistinen/a887098974702041bc9c to your computer and use it in GitHub Desktop.
This is like render_model_block but for plugins!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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