[Answered ]-Request.user not available in Streamblocks subtemplate

1👍

When outputting the StreamField onto the page, be sure to use the include_block tag rather than just outputting the value within a {{ ... }} tag. This ensures that any variables defined on the outer template, including request, are passed on to the sub-template. If you use {{ ... }}, the sub-template will still be rendered, but the only available variables are the ones supplied by the block itself.

{% include_block %} can be used on an individual block, or the stream as a whole:

{% load wagtailcore_tags %}

{% include_block page.body %}

or

{% for block in page.body %}
    {% include_block block %}
{% endfor %}

You’ll also need to do this within any sub-templates that render sub-sub-templates (for example, if you have a nested StreamBlock within the StreamField, the template for that StreamBlock needs to use include_block too).

👤gasman

Leave a comment