Skip to content

Instantly share code, notes, and snippets.

@dwickstrom
Created June 22, 2016 10:00
Show Gist options
  • Save dwickstrom/1b8613b6e02d165c0a326731e53785dd to your computer and use it in GitHub Desktop.
Save dwickstrom/1b8613b6e02d165c0a326731e53785dd to your computer and use it in GitHub Desktop.
Workaround for the inability to access the full context inside a block inside a StreamField in Wagtail
{% for block in self.body %}
<section class="{{ block.block_type }}">
{% if block.block_type == 'fooblock' %}
{% get_foo block.value request %}
{% else %}
{{ block}}
{% endif %}
</section>
{% endfor %}
@register.inclusion_tag('home/tags/foo.html', takes_context=True)
def get_foo(context, block, request):
return {
'block': block,
'request': context['request'],
}
# foo.html
<section>
{{ request }}
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment