Gutenberg: How to use output of php render_callback function in the block editors backend?

I think that you are missing the PHP registration of the block.

The JS definition is all right, but you need to tell PHP that the block exists.

Can you try to register your block in your plugin or function.php file?

Here is an example https://developer.wordpress.org/block-editor/tutorials/block-tutorial/creating-dynamic-blocks/

<?php

function simpletoc_toc_render_callback( $attributes, $content ) {
    return 'This is my block content'.
}

function simpletoc_toc_register_block() {
    register_block_type( 'simpletoc/toc', array(
        'render_callback' => 'simpletoc_toc_render_callback'
    ) );

}
add_action( 'init', 'simpletoc_toc_register_block' );

Note that the code above is shortened to the essential.

EDIT Sorry, didn’t realized that all the magic for the backend rendering was coming from ACF Plugin.

You might want to have a look at this.
https://developer.wordpress.org/block-editor/packages/packages-server-side-render/ Though I have no idea on how to use it.

Leave a Comment