How to register Gutenberg blocks using acf_register_block_type

Have read up on using plugins to register blocks in Sage 10 but I was wondering if there is a way to register Guternberg blocks using the more traditional method of acf_register_block_type.

So far, I’ve created a new file: acf-blocks.php in the /app folder and have the acf/init action to register them. So an example would be:

/resources/views/blocks/banner.php

And have registered it successfully with:

acf_register_block_type(array(
        'name'              => 'banner',
        'title'             => __('Banner'),
        'description'       => __('Banner Block'),
        'render_template' => \Roots\view('blocks.banner')->render(),
        'category'          => 'media',
        'icon'              => 'images-alt2',
        'supports'          => array('align' => array('wide')),
        'align'             => 'wide'
      ));

The blocks are registered in the CMS fine and I can use them in the editor, however they are not rendering in the front-end and I’m sure the render_template isn’t right.

I’ve searched and tried numerous paths to no avail. Is there anyone who has successfully got their blocks working in the front-end using this way of registering acf blocks?

I don’t mind it they have to run as Blade or not. Any help would be appreciated. :+1:t2:

I sorted this with the following line:

'render_template'   =>  config('theme.dir') . '/resources/views/blocks/banner/banner.php',

Just to add to this, make sure you are calling a standard php file in 'render_template' and not a .blade.php like I was :grin:

1 Like