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
1 Answer
Reset to default 0Blocks 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
版权声明:本文标题:Innerblocks isn't adding new blocks when template changes 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736641122a1945996.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论