我创建了一个用wp-cli调用的自定义块类型,它可以正常工作,但是当我向其添加innerBlocks时,会显示innerBlocks,但是除了模板,templateLock和allowedBlocks之外,不保存或遵守其他任何属性所有被忽略。同样,当我将wp.editor.InnerBlocks定义为变量时,它返回null,但是如果我将其包含在块编辑部分中,它可以正常工作,但仍然无法保存。完整代码:
( function( wp ) {
var registerBlockType = wp.blocks.registerBlockType,
__ = wp.i18n.__,
el = wp.element.createElement
;
registerBlockType( 'adventures/accommodations', {
title: __( 'Accommodations' ),
icon: 'admin-multisite',
category: 'layout',
supports: {
html: false,
align: true
},
attributes: {
align: {
type: 'string',
default: 'full'
},
},
edit: function( props ) {
var attributes = props.attributes;
return [
el( 'div', {className: props.className,},
el( 'h2', {className: 'sub-header'},
'Accommodations'
),
el( wp.editor.InnerBlocks, {
allowedBlocks: ['core/columns', 'core/column', 'core/paragraph', 'core/gallery'],
template: [
['core/columns', {},[
['core/column', {}, [
['core/gallery']
]],
['core/column', {},[
['core/paragraph', { placeholder: 'Enter short description...' }]
]]
]]
],
templateLock: 'all'
}),
)
]
},
save: function( props ) {
var attributes = props.attributes;
var InnerBlocks = props.innerBlocks
return [
el( 'div', {className: props.className,},
el( 'h2', {className: 'sub-header'},
'Accommodations'
),
el( InnerBlocks.Content ),
)
]
}
});
} )(
window.wp
);
旁注,也尝试在没有块对齐控件的情况下使块对齐全宽,但是找不到有关该操作的任何文档。任何帮助将不胜感激,谢谢!