Sunday, July 24, 2022
HomeWordPress DevelopmentGutenberg template lock however add/delete blocks programmatically

Gutenberg template lock however add/delete blocks programmatically


I’m utilizing the templateLock property to lock down the template of an interior block:

edit: () => {
     return (
         <InnerBlocks
             template={ MY_TEMPLATE }
             templateLock="all"
         />
     );
 },

I’m not permitting to insert new blocks or delete them.

Nonetheless I wish to add or delete blocks programmatically, for instance utilizing:

wp.knowledge.dispatch("core/block-editor").removeBlock( blockClientId );

This doesn’t work as a result of the template lock prevents all operations. Is it doable to lock the template however nonetheless be capable of add/delete the kid blocks programmatically?

I do know it’s doable to lock particular person blocks with the brand new lock attribute, however this provides a lock icon to the blocks, additionally the likelihood to uncheck locking. I don’t want the person to see any add or delete block UI, or be confused by the lock icon.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments