wagtailwagtail-streamfieldwagtail-admin

How to Disable Certain Block Types in Wagtail's StreamField Based on Selected Theme?


In the editor's interface I have a field where the editor can choose a theme for his Page: Theme field

The theme defines the styles for the blocks created in the StreamField "body" when the Page is served, however there are some themes which do not support certain block types and I would like to disable these blocks as an option when the "insert block" button is clicked.

E.g: Disable or delete the "Benefits" block in the combobox when the theme Homestate is selected: Insert block combobox

Does wagtail allows this kind of customization at all?


Solution

  • Out of the box Wagtail does not support reconfiguring your StreamField body on the fly. In my project we have a StreamBlock subclass that allows us to enable / disable certain blocks based on feature flags. But in our case, we know what blocks to enable/disable when the page is loaded. I don't know how you would change the features offered based on a value within the same page.

    The code I am referring to is here - in case it helps.