diff --git a/wagtail/tests/testapp/blocks.py b/wagtail/tests/testapp/blocks.py index c598e6bc71..a0df558c70 100644 --- a/wagtail/tests/testapp/blocks.py +++ b/wagtail/tests/testapp/blocks.py @@ -12,3 +12,11 @@ class LinkBlock(blocks.StructBlock): class Meta: template = 'tests/blocks/link_block.html' + + +class SectionBlock(blocks.StructBlock): + title = blocks.CharBlock() + body = blocks.RichTextBlock() + + class Meta: + template = 'tests/blocks/section_block.html' diff --git a/wagtail/tests/testapp/templates/tests/blocks/section_block.html b/wagtail/tests/testapp/templates/tests/blocks/section_block.html new file mode 100644 index 0000000000..60a2f6e834 --- /dev/null +++ b/wagtail/tests/testapp/templates/tests/blocks/section_block.html @@ -0,0 +1 @@ +

{{ value.title }}

{{ value.bound_blocks.body.render }} \ No newline at end of file diff --git a/wagtail/wagtailcore/tests/test_blocks.py b/wagtail/wagtailcore/tests/test_blocks.py index 3e289ee8ca..7eaf74ff43 100644 --- a/wagtail/wagtailcore/tests/test_blocks.py +++ b/wagtail/wagtailcore/tests/test_blocks.py @@ -13,6 +13,8 @@ from wagtail.wagtailcore import blocks from wagtail.wagtailcore.rich_text import RichText from wagtail.wagtailcore.models import Page +from wagtail.tests.testapp.blocks import SectionBlock + import base64 @@ -714,6 +716,16 @@ class TestStructBlock(SimpleTestCase): with self.assertRaises(ValidationError): block.clean(value) + def test_bound_blocks_are_available_on_template(self): + """ + Test that we are able to use value.bound_blocks within templates + to access a child block's own HTML rendering + """ + block = SectionBlock() + value = block.to_python({'title': 'Hello', 'body': 'italic world'}) + result = block.render(value) + self.assertEqual(result, """

Hello

italic world
""") + class TestListBlock(unittest.TestCase): def test_initialise_with_class(self):