admin管理员组

文章数量:1124812

I have 2 custom blocks, "super-tabs" and "super-tab". Tabs has an inspector control that determines how many tab blocks will be in the tabs block. But when I change the number of tabs, it doesn't change the number of tab blocks. How do I make it do that?

My code looks like this:

let defaultChildren = [];
for (let i = 1; i <= numTabs; i++) {
    defaultChildren.push(["super-tabs/super-tab", {}, [["core/paragraph",{content:'Tab'+i}]]]);
}

...

return wp.element.createElement(wp.blockEditor.InnerBlocks, {template: defaultChildren})

I have 2 custom blocks, "super-tabs" and "super-tab". Tabs has an inspector control that determines how many tab blocks will be in the tabs block. But when I change the number of tabs, it doesn't change the number of tab blocks. How do I make it do that?

My code looks like this:

let defaultChildren = [];
for (let i = 1; i <= numTabs; i++) {
    defaultChildren.push(["super-tabs/super-tab", {}, [["core/paragraph",{content:'Tab'+i}]]]);
}

...

return wp.element.createElement(wp.blockEditor.InnerBlocks, {template: defaultChildren})
Share Improve this question asked Feb 23, 2024 at 3:18 CoomieCoomie 1416 bronze badges 1
  • Are you trying to replicate the behaviour of the Columns block? You can see how that block does it here: github.com/WordPress/gutenberg/blob/trunk/packages/… You just need to ignore the stuff about widths. – Jacob Peattie Commented Feb 23, 2024 at 7:56
Add a comment  | 

1 Answer 1

Reset to default 0

Blocks won't be created or removed unless the template is locked.

To lock the template add this argument to the InnerBlocks

wp.element.createElement(wp.blockEditor.InnerBlocks, {template: defaultChildren, templateLock: "all"})

本文标签: Innerblocks isn39t adding new blocks when template changes