1
votes

I have the following very simple statement to render blocks in wagtail.

{% for block in blocks %}
    {% include_block block %}
{% endfor %}

The for loop works and iterates over the blocks as does the template tag include_block. The variable 'block' however is not accessible in the template executed by include_block.

{% set background_image = block.background_image.image %}

The above statement called in the template called by include_block throws the following error.

'block' is undefined

This does not really make sense since the documentation for Wagtail's include_block states that variables get passed down into the called template.

http://docs.wagtail.io/en/v1.9/advanced_topics/jinja2.html#include-block

I have the following statement in order to explicitly pass in variables but it still does not work,

 {% include_block block with context %}
1

1 Answers

2
votes

It is indeed surprising that block doesn't get passed down and might constitute a bug (edit: see comments below for further discussion on that matter)

That being said, in a block template, the block value is accessible as the variable value (see 6th paragraph of the StreamField template rendering section).