1

我创建了一个用 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
);

旁注,也试图在没有块对齐控件的情况下使块对齐全宽,但找不到任何关于如何做到这一点的文档。任何帮助将不胜感激,谢谢!

4

0 回答 0