admin管理员组文章数量:1321597
I would like to create a custom block that contains columns, and starts with various other blocks in each of the columns, however the code I have come up with so far will create a column block in the same way that adding a new column block from the standard block library does, i.e. asking which column variation, and even if I click skip it just gives me empty columns rather than my default content.
The code does the same thing even if I remove the innerBlocks
property altogether, and renaming it to content does not help either. There are no console errors in the browser, or in the npm build process.
Adding content into the default columns the code gives me works, and I can save/reload/edit fine, just can't specify default content.
I am running the latest WordPress 5.5.
import {__} from '@wordpress/i18n';
import {registerBlockType} from '@wordpress/blocks';
import {InnerBlocks} from '@wordpress/block-editor';
const MY_TEMPLATE = [
['core/columns', {
columns: 2,
innerBlocks: [
['core/column', {
width: 33.33, innerBlocks: [
['core/paragraph', {
placeholder: 'LHS Column',
content: __(
'LHS Lorem ipsum.....'
)
}]
]
}],
['core/column', {
width: 66.66, innerBlocks: [
['core/paragraph', {
placeholder: 'RHS Column',
content: __(
'RHS Lorem ipsum.....'
)
}]
]
}]
]
}]
]
registerBlockType('my/block', {
title: __('my block', 'my-block'),
icon: 'feedback',
category: 'layout',
edit: (props) => {
return (
<div>
<InnerBlocks
template={MY_TEMPLATE}
templateLock="all"
orientation="horizontal"
/>
</div>
);
},
save: ({attributes}) => {
return (
<div>
<InnerBlocks.Content/>
</div>
);
}
});
本文标签: plugin developmentCreating a custom Gutenberg block with columns
版权声明:本文标题:plugin development - Creating a custom Gutenberg block with columns 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742105561a2421002.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论