【发布时间】:2021-11-13 17:18:39
【问题描述】:
我正在使用 @wordpress/server-side-render 从后端获取 Gutenberg 块的内容。
if ( props && props.attributes ) {
blockContent = <ServerSideRender
block="test/employee-block"
attributes={ props.attributes }
/>
}
这里是块的 PHP 端
register_block_type( 'test/employee-block', array(
'title' => 'Test Block',
'description' => 'test',
'category' => 'widgets',
'icon' => 'admin-users',
'api_version' => 2,
'editor_script' => 'employees_dynamic_block_script',
'render_callback' => function ($block_attributes, $content) {
return '<h1>test</h1>';
}
) );
但是,渲染回调函数的 $block_attributes 始终为空。我不知道为什么,但根据API documentation,它应该在那里。
【问题讨论】:
-
没有,但我找到了解决方案
标签: php reactjs wordpress wordpress-gutenberg gutenberg-blocks