我想Section
在 WordPress Gutenberg 中做一个块。我创建了一个部分块并将 Gutenberg<InnerBlocks>
组件用作内部/子块。它工作正常,但Section
块本身显示为其内部块列表。我想Section
从其内部块中排除该块。<InnerBlocks>
组件有一个属性allowedBlocks
来指定允许作为内部块的块。但这对我没有帮助,因为我只想禁止Section
来自内部块的块。我怎样才能只禁止一个特定的块<InnerBlocks>
?
我需要一个选项,disallowedBlocks
这样我就可以从 innerBlocks 列表中排除块,例如
<InnerBlocks disallowedBlocks={['leo-block/section']} />
完整代码
;(function(wp) {
const {registerBlockType} = wp.blocks;
const {InnerBlocks} = wp.editor;
const {__} = wp.i18n;
registerBlockType('leo-block/section', {
title: __('Section'),
icon: 'grid-view',
category: 'vr-blocks',
descrition: __('Section block for manage content section'),
attributes: {
content: {
default: 'Hello World'
},
spacing: {
default: {
paddingTop: '70px',
paddingBottom: '70px',
marginTop: '0',
marginBottom: '0'
}
}
},
edit: ({attributes, setAttributes, className, isSelected}) => {
return (
<section className = {className} style={attributes.spacing}>
<div className="container">
<InnerBlocks/>
{/* TODO: Not allow "leo-block/section" */}
</div>
</section>
)
},
save: ({attributes, className}) => {
return (
<section className = {className} style={attributes.spacing}>
<div className="container">
<InnerBlocks.Content/>
</div>
</section>
)
}
})
})(window.wp)
输出截图