我想使用带有 create-guten-block 的古腾堡服务器端渲染一个简单的模板。
初始化.php:
function melaniemueller_templateparts_block_cgb_block_assets() {
register_block_type(
'cgb/block-melaniemueller-templateparts-block', array(
'render_callback' => 'mmu_block_render',
)
);
}
}
// Hook: Block assets.
add_action( 'init', 'melaniemueller_templateparts_block_cgb_block_assets' );
function mmu_block_render($attr, $content) {
locate_template( 'custom\php\templates\header\header_main_1.php', true );
}
块.js:
registerBlockType( 'cgb/block-melaniemueller-templateparts-block', {
// Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block.
title: __( 'melaniemueller-templateparts-block - CGB Block' ), // Block title.
icon: 'shield', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/.
category: 'common', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed.
keywords: [
__( 'melaniemueller-templateparts-block — CGB Block' ),
__( 'CGB Example' ),
__( 'create-guten-block' ),
],
edit: function( { attributes } ) {
return (
<ServerSideRender
block="cgb/block-melaniemueller-templateparts-block"
attributes={ attributes }
/>
);
},
save: function( { } ) {
return null;
},
} );
但是,如果我想渲染这部分,我会edit
在 Chrome 的 Quirks-Mode 中的 -function 中遇到一个错误。
Error loading block: The response is not a valid JSON response.
有谁知道我做错了什么?