I'm using Builder to create a small library of Gutenberg blocks, mostly because I'd like to use twig. I intend to use these blocks with multiple sites, so I'm hoping to create a block library plugin.
I've created a simple block in Builder with a single text field and a very simple twig rendering. It appears as expected in the block selector, the field shows up as expected in the sidebar, and the block renders as expected in the editor and on the front end once the field has content.
Then I generate PHP for the block in Builder and add it to my plugin. I expect that the block will act the same way: show up in the selector, show the field in the sidebar, and render in the editor and the frontend once the field has content.
That's not what happens. It does appear in the block selector. It does show the field in the sidebar. So it registers properly. But when I enter content, the block does not render in the editor. And it does not render on the front end. There is no code at all for the block in the inspector.
I'm puzzled as to why this is.
Here is the PHP block code:
<?php
add_filter( 'rwmb_meta_boxes', 'register_test_block_php' );
function register_test_block_php( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'Test Block - PHP', 'your-text-domain' ),
'id' => 'test-block-php-14',
'icon' => 'flag',
'category' => 'text',
'keywords' => ['block test'],
'supports' => [
'align' => [''],
],
'render_code' => '<div class="test_block">Field text: {{ php_block_field_text }}</div>',
'type' => 'block',
'context' => 'side',
'fields' => [
[
'name' => __( 'Field Text', 'your-text-domain' ),
'id' => $prefix . 'php_block_field_text',
'type' => 'text',
],
],
];
return $meta_boxes;
}
Just to be clear, I changed the ID of the block and of the field so there wouldn't be a conflict with the Builder-generated block.
I'm sure there's something simple I'm missing, but I'd love your help in figuring out what.
Thanks!