Adding default ACF Blocks to a Post Template

Hello,

I’m using the following plugin for adding ACF blocks - https://github.com/MWDelaney/sage-acf-wp-blocks

I have created three separate blocks that I would like to add by default to a custom Post template I have. (e.g. a user will create a new post and the three ACF blocks will be preloaded and empty by default)

Any idea if it’s possible to preset ACF blocks for a given post/page template?

If I understood correctly, you want the blocks to appear already on selected post/page templates, and in certain order but without any content? Never had to do that before, but perhaps this is what you are looking for? https://developer.wordpress.org/block-editor/developers/block-api/block-templates/

Basically I have a several Post Templates, one of which is a three column layout.

I really like the Gutenburg look and feel, so I wanted three sections pertaining to each column to appear when someone selects the “three column layout” post template.

I have tried your link and also this one https://www.billerickson.net/gutenberg-block-templates/ however there seems to be a specific way that it needs to be registered for the sage-acf-wp-blocks plugin

Not so sure about the specifics for sage-acf-wp-blocks plugin, but it would probably help people if you show what you have tried and what doesn’t work as expected?

Part of the problem is that I know what I want to do, but I have no idea how to achieve it. I want to render the block I’ve created in a specific post template.

I tried the below code in the link provided in my last post in filters.php. When testing to see if anything is set, nothing renders or happens and I’ve tried calling the blog which is in /views/blocks/ in a number of different ways.

function be_post_block_template() {
  $post_type_object = get_post_type_object( 'post' );
  $post_type_object->template = array(
    array( 'core/paragraph' ),
    array( 'acf/hero' ),
    array( 'core/paragraph' ),
    array( 'acf/hero' ),
    array( 'core/paragraph' ),
  );
}
add_action( 'init', __NAMESPACE__ .'\\be_post_block_template' );

When reading the docs for the sage-acf-wp-blocks plugin https://github.com/MWDelaney/sage-acf-wp-blocks

There is an example of a filter - however this doesn’t help me as I want to render the block rather then change any data about it.

add_filter('sage/blocks/my-block/data', function ($block) { 
  // logic goes here    
});

I’ve dug through the plugin code but I’m not quite sure what the method/function is that I need to pull out to be able to render the block inside my post template.

I was hoping @MWDelaney could chime in - since this plugin was developed based off a post in these forums.

This topic was automatically closed after 42 days. New replies are no longer allowed.