3

The title pretty much says it all. I am working on a custom Gutenberg block that utilizes the InnerBlocks component and I have defined some allowed and default blocks. I also have templateLock set to all so the user cannot add, remove or move blocks around. However, this settings is affecting the core/buttons block and your ability to add a new button (since this block made up of individual core/button blocks).

Is there any way around this? Is there a way to specifically exclude the core/buttons blocks from the templateLock setting?

Below you will find my edit function for the block.

edit: function (props) {
    const { className, clientId } = props;

    /**
     * Add Item
     */
    const onRemoveItem = () => {
        setAttributes({ items: parseInt(`${items}`) - 1 })
        removeBlock(clientId)
    }

    return (
        <Fragment>
            <div className='listicles-innerblocks' >
                <InnerBlocks
                    template={[
                        ['core/cover'],
                        ['custom/listdt'],
                        ['core/buttons'],
                        ['custom/listdd'],
                    ]}
                    allowedBlocks={[
                        ['core/cover'],
                        ['custom/listdt'],
                        ['core/buttons'],
                        ['custom/listdd']
                    ]}
                    templateLock={'all'}
                />
            </div>
        </Fragment>
    );
},
1
  • Did you ever find a solution to this?
    – Shoelaced
    Feb 7 at 15:49

1 Answer 1

3

core/buttons is a container block, it's not the actual buttons. Instead, core/buttons contains core/button blocks. The same way that a core/columns block contians core/column blocks.

You need to add core/button to your allowed blocks list.

2
  • Unfortunately this does not work. I don't get the plus icon to add a button to the buttons core block. If I remove the templateLock then I will see the plus sign. Mar 16, 2022 at 16:54
  • have you considered not fully locking the template down? There was a blog post on the official Make WP blog at wordpress.org about locking individual blocks and patterns recently in WP 5.9, right now you're passing a template but you've said nothing about the attributes or contents of the blocks in your template
    – Tom J Nowell
    Mar 17, 2022 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.