Support

Account

Home Forums Gutenberg Calling a Reusable ACF Block in a Block Template

Helping

Calling a Reusable ACF Block in a Block Template

  • Hi All,
    I’ve created a simple ACF block for a call to action and have saved a reusable version of it in Gutenberg. From there, I want that reusable block to automatically be added to every new post created.

    After doing some research, I implemented the following code:

    // Add Default Blocks Where Needed
    function ovyvo_register_template() {
        $post_type_object = get_post_type_object( 'post' );
        $post_type_object->template = array(
            array(
    			'acf/ovyvo-cta-noimage', array(
    				'ref' => 290,// Reusable block id
    			),
    		),
        );
    }
    add_action( 'init', 'ovyvo_register_template' );

    Notice I’m using the ID of the reusable block (290). However, whenever I add a new post, I just get a blank version of the block. The following error comes up in the console:

    Uncaught TypeError: can’t access property “buttons”, n is undefined – acf-input.min.js:4:8414

    I’m assuming this means it can’t access the content? I previously had the block restricted to specific post types, but have removed that. I should also note that adding the reusable block within Gutenberg works just fine – it’s just getting it added via this template.

    Any suggestions as to what else may cause this?

    Thanks!

  • Not sure if anybody needs this, but I believe these reusable blocks are saved under core/block. So the above code should be changed to

    
    $post_type_object->template = array(
            array(
    			'core/block', array(
    				'ref' => 290,// Reusable block id
    			),
    		),
        );
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.