1

这在 Gutenberg 3 上运行良好:

function render_block($attrs, $content){
    ob_start();
        echo $content;
    return ob_get_clean();
}

但是随着最近的 Gutenberg 更新,$content它始终为 null,即使从保存回调将其传递为:

    save: function(props) {
        return el( InnerBlocks.Content );
    },

任何帮助深表感谢。

4

2 回答 2

0

它实际上是古腾堡本身的一个错误,并在 WP 5.1.1 中修复

谢谢

于 2019-04-11T09:58:26.233 回答
-1

块.js

(function (blocks, editor, components, i18n, element) {

    var el = element.createElement;

    blocks.registerBlockType('block-category/block-name', {

        ...

        edit: function(props) {

            el(editor.InnerBlocks, {
                allowedBlocks: ['core/heading'],
                template: [['core/heading', {'placeholder':'Placeholder text'}]],
            })

        },

        save: function(props) {

            return el(editor.InnerBlocks.Content);

        }

    });

})(
  window.wp.blocks,
  window.wp.editor,
  window.wp.components,
  window.wp.i18n,
  window.wp.element
);

块.php

add_action('init', function() {

    wp_register_script(
        'block_script',
        plugins_url('block.js', __FILE__),
        array('wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor'),
        filemtime(plugin_dir_path(__FILE__) . 'block.js'),
        true
    );

    'editor_script' => 'block_script',

    register_block_type('block-category/block-name', array(

        'render_callback' => function($attributes, $content) {

            return $content;

        }

    ));

});
于 2019-04-11T00:04:30.367 回答