Support

Account

Home Forums Gutenberg block templates – best practice?

Solving

block templates – best practice?

  • Hello,

    I want the user to select a page-template and get a set of predefined ACF Gutenberg blocks. How can I achieve this ?

    Or is this the wrong approach and I should use the Gutenberg “Pattern” feature and not rely on page-templates?

    Any suggestions or ideas?
    Best
    P.

  • This is a WP question and you’re more likely to get an answer from them. However, it seems that it’s not possible https://wordpress.org/support/topic/how-to-create-block-templates-for-specific-page-templates/

  • I don’t know if its possible to connect it to a certain page template , it would be great if it was possible. But at least its possible to set predefined blocks to a post or page or custom post type.

    Just add this function:

    function myplugin_register_template() {
        $post_type_object = get_post_type_object( 'page' );
        $post_type_object->template = array(
            array( 'acf/block1' ), // the name of your block
            array( 'acf/block2' ), // the name of your block
        );
    }
    add_action( 'init', 'myplugin_register_template' );
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.