Support

Account

Home Forums Gutenberg Define ACF Block in CPT template

Unread

Define ACF Block in CPT template

  • Is it not possible to use an ACF block in a predefined template for an CPT?
    Just use the ACF example block as decribed here: https://www.advancedcustomfields.com/resources/acf_register_block_type/

    add_action('acf/init', 'my_acf_blocks_init');
    function my_acf_blocks_init() {
    
        // Check function exists.
        if( function_exists('acf_register_block_type') ) {
    
            // Register a testimonial block.
            acf_register_block_type(array(
                'name'              => 'testimonial',
                'title'             => __('Testimonial'),
                'description'       => __('A custom testimonial block.'),
                'render_template'   => 'template-parts/blocks/testimonial/testimonial.php',
                'category'          => 'formatting',
            ));
        }
    }

    and then try to use that registered block in a template. E.g. as described in the following example:

    
    // Predefine Gutenberg Template & lock them
    // @see https://developer.wordpress.org/block-editor/developers/block-api/block-templates/
    
       'template_lock' => 'all',
          'template' => array(
            array( 'acf/testimonial', array(
            ) ),
        ),
    

    Doing so, Gutenberg is not loading anymore and outputs the JS error TypeError: can't access property "attributes", blockType is undefined.
    My guess is that the loading is not in the correct order. So how would I get this working?

    Thanks and kind regards

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.