From 207e9e50d9f3beafdbfa576332a11a69f4e28728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A6var=20=C3=96fj=C3=B6r=C3=B0=20Magn=C3=BAsson?= Date: Fri, 18 Oct 2024 11:05:29 +0000 Subject: [PATCH] StaticBlock renders empty in templates (#12425) --- CHANGELOG.txt | 1 + docs/releases/6.3.md | 1 + wagtail/blocks/static_block.py | 3 +++ wagtail/tests/test_blocks.py | 5 +++++ 4 files changed, 10 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3d52101261..2b52ee7299 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -128,6 +128,7 @@ Changelog * Add "soft" client-side validation for `StreamBlock` / `ListBlock` `min_num` / `max_num` (Matt Westcott) * Log accessibility checker results in the console to help developers with troubleshooting (Thibaud Colas) * Disable pointer events on checker highlights to simplify DevTools inspections (Thibaud Colas) + * `StaticBlock` now renders nothing by default when no template is specified (Sævar Öfjörð Magnússon) * Fix: Make `WAGTAILIMAGES_CHOOSER_PAGE_SIZE` setting functional again (Rohit Sharma) * Fix: Enable `richtext` template tag to convert lazy translation values (Benjamin Bach) * Fix: Ensure permission labels on group permissions page are translated where available (Matt Westcott) diff --git a/docs/releases/6.3.md b/docs/releases/6.3.md index 3038e84b7d..116a26e7e7 100644 --- a/docs/releases/6.3.md +++ b/docs/releases/6.3.md @@ -71,6 +71,7 @@ This feature was developed by Bart Cieliński, alexkiro, and Sage Abdullah. * Prompt the user about unsaved changes when editing snippets (Sage Abdullah) * Add support for specifying different preview modes to the "View draft" URL for pages (Robin Varghese) * Implement new designs for the footer actions dropdown with more contrast and larger text (Sage Abdullah) + * `StaticBlock` now renders nothing by default when no template is specified (Sævar Öfjörð Magnússon) ### Bug fixes diff --git a/wagtail/blocks/static_block.py b/wagtail/blocks/static_block.py index 85fb0c5835..88ca712481 100644 --- a/wagtail/blocks/static_block.py +++ b/wagtail/blocks/static_block.py @@ -33,6 +33,9 @@ class StaticBlock(Block): def normalize(self, value): return None + def render_basic(self, value, context=None): + return "" + class Meta: admin_text = None default = None diff --git a/wagtail/tests/test_blocks.py b/wagtail/tests/test_blocks.py index adcf0e097c..f53430a4fb 100644 --- a/wagtail/tests/test_blocks.py +++ b/wagtail/tests/test_blocks.py @@ -5015,6 +5015,11 @@ class TestStaticBlock(unittest.TestCase): result = block.render(None) self.assertEqual(result, "

PostsStaticBlock template

") + def test_render_without_template(self): + block = blocks.StaticBlock() + result = block.render(None) + self.assertEqual(result, "") + def test_serialize(self): block = blocks.StaticBlock() result = block.get_prep_value(None)