Last active
October 25, 2016 05:34
-
-
Save mgd020/d841f8016024707b11b490b82ec648f0 to your computer and use it in GitHub Desktop.
Registers render_streamfield tag to add current context to streamfield block templates.
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
''' | |
Registers render_streamfield tag to add current page context to all block templates. | |
Usage: {% render_streamfield a_streamfield %} | |
Author: github.com/mgd020 | |
''' | |
from django import template | |
from wagtail.wagtailcore.blocks.base import Block | |
register = template.Library() | |
@register.simple_tag(takes_context=True) | |
def render_streamfield(context, value): | |
def get_context(self, value): | |
return dict(context.flatten(), **{ | |
'self': value, | |
self.TEMPLATE_VAR: value, | |
}) | |
Block.get_context = get_context | |
return str(value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting.