WordPress Gutenberg-使用模板中的自定义块类别的页面编辑屏幕上的白屏

问题描述 投票:1回答:1

我正在尝试设置模板并使用自定义类别中包含的块。在古腾堡(Gutenberg)编辑器中正常使用时,块词a-ok。

我这样创建类别:

add_filter( 'block_categories', function( $categories, $post ) {
 return array_merge(
   $categories,
   array(
     array(
       'slug'  => 'mycustomcat',
       'title' => 'My Custom Category',
     ),
   )
 );
}, 10, 2 );

并制作(ACF)块:

    acf_register_block_type(array(
        'name'              => 'column-text',
        'title'             => __('Column Text'),
        'render_template'   => 'template-parts/blocks/column-text-block.php',
        'category'          => 'mycustomcat',
        'icon'              => 'menu-alt2',
        'keywords'          => array( 'column', 'text' ),
        'post_types'        => $supportedPostTypes,
        'mode'              => 'auto',
        'supports'          => array( 'align' => false ),
    ));

直到我们到达这里一切都很好:

function myplugin_register_template() {
   $post_type_object = get_post_type_object( 'page' );
   $post_type_object->template = array(
       array( 'mycustomcat/column-text' ),
   );
}
add_action( 'init', 'myplugin_register_template' );

然后,在WordPress管理员中创建新页面时,出现空白屏幕。发现的唯一错误是在控制台中:

Uncaught (in promise) TypeError: Cannot read property 'attributes' of undefined
    at Te (blocks.min.js?ver=6.7.2:2)
    at blocks.min.js?ver=6.7.2:2
    at c (lodash.min.js?ver=4.17.15:6)
    at ru (lodash.min.js?ver=4.17.15:67)
    at pn (blocks.min.js?ver=6.7.2:2)
    at editor.min.js?ver=9.7.5:11
    at u (editor.min.js?ver=9.7.5:11)
    at Generator._invoke (editor.min.js?ver=9.7.5:11)
    at Generator.forEach.e.<computed> [as next] (editor.min.js?ver=9.7.5:11)
    at redux-routine.min.js?ver=3.6.2:1
wordpress advanced-custom-fields wordpress-gutenberg gutenberg-blocks acfpro
1个回答
0
投票

对于其他有相同问题的人。 Acf块名称必须使用acf / blockname进行命名空间。

在这种情况下,array('mycustomcat / column-text')应该是array('acf / column-text')。

© www.soinside.com 2019 - 2024. All rights reserved.