I'm trying to build a custom Gutenberg Block, which will be rendered dynamically (from PHP).
I've spent a significant amount of time searching for different solutions, minimized my code to the absolutely necessary, and still it doesnt work.
My main reference is this page: <a href="https://developer.wordpress.org/block-editor/tutorials/block-tutorial/creating-dynamic-blocks/" rel="nofollow noreferrer">https://developer.wordpress.org/block-editor/tutorials/block-tutorial/creating-dynamic-blocks/</a>
And here's my code:
PHP (functions.php):
test-block.js:
i really have no idea why this isn't working as its supposed to, on the frontend the block is just not rendered at all, not even a comment or anything. Oh and my current WP Version is 5.5.3 with PHP 7.3 if this helps..
Does anyone know why my block isn't rendering? Thanks!
I've spent a significant amount of time searching for different solutions, minimized my code to the absolutely necessary, and still it doesnt work.
My main reference is this page: <a href="https://developer.wordpress.org/block-editor/tutorials/block-tutorial/creating-dynamic-blocks/" rel="nofollow noreferrer">https://developer.wordpress.org/block-editor/tutorials/block-tutorial/creating-dynamic-blocks/</a>
And here's my code:
PHP (functions.php):
Code:
function register_test_block(){
wp_register_script('test-block',
get_template_directory_uri().'/js/test-block.js',
array('wp-blocks') );
register_block_type('test/testblock', array(
'render_callback' => function( $block_attributes, $content ) {
return '<p>OMG SUCCESS!</p>';
},
'editor_script' => 'test-block' )
);
}
add_action('init', 'register_test_block');
Code:
const { registerBlockType } = wp.blocks;
registerBlockType('test/testblock', {
title: 'test block',
edit: props => {
return (<p>test</p>);
},
save: props => {
return null;
}
});
Does anyone know why my block isn't rendering? Thanks!