Gutenberg template lock but add/delete blocks programmatically
I am using the templateLock property to lock down the template of an inner block:
edit: () => {
return (
<InnerBlocks
template={ MY_TEMPLATE }
templateLock="all"
/>
);
},
I am not allowing to insert new blocks or delete them.
However I would like to add or delete blocks programmatically, for example using:
wp.data.dispatch("core/block-editor").removeBlock( blockClientId );
This does not work because the template lock prevents all operations. Is it possible to lock the template but still be able to add/delete the child blocks programmatically?
I know it is possible to lock individual blocks with the new lock attribute, but this adds a lock icon to the blocks, also the possibility to uncheck locking. I do not want the user to see any add or delete block UI, or be confused by the lock icon.
Leave an answer