Does the block editor need a client side alternative to the render_block
filter?
#63876
Replies: 2 comments 1 reply
-
Some other considerations:
|
Beta Was this translation helpful? Give feedback.
-
I think this is a very difficult problem, because blocks that exist on the block editor are React components. Gutenberg has a system called SlotFill, which allows us to inject new React elements through pre-prepared slots in React components. Examples include the block toolbar and inspector control. On the other hand, blocks on the block editor are As far as I know, the only way to modify the |
Beta Was this translation helpful? Give feedback.
-
If you want to modify/enhance core block functionality, it's pretty easy to change CSS inside the block editor, with custom attributes, block styles, etc. In fact, the serialized data of attributes (including
className
) is about the only thing you can safely modify on a core block.If you want to change the HTML markup of a core block, that's also fairly doable with the
render_block
filters that run during the server-side render, typically by checking the values of your custom attributes.However, if you want to see HTML markup changes inside the block editor, you have to be very careful. You can modify the block's HTML while inside the editor using existing filters, but that altered markup is then saved to the database, meaning once you disable your plugin, the markup is considered "invalid" and the block appears broken.
This makes it really hard to modify blocks in ways that might require structural changes, like adding SVGs (ex: adding an SVG arrow to a button variation).
Would a block editor version of
render_block
- a filter that modifies what you see in the editor but those modifications are not saved to the database- be useful? You'd have to replicate your work twice, (once in JS and once in PHP) but I guess we're all used to that now!CC @ndiego
Beta Was this translation helpful? Give feedback.
All reactions