How to specify which Gutenberg blocks are available in the editor for a page template

Using an example given here: enter link description here I’ve successfully been able to restrict the block types available globally or by post type (eg: page). But what I really would like to do is restrict the the block types by page template.
I have tried using if ( is_page_template(‘page-home.php’) ) {…} but with no joy. It will be apparant from the code below, but I am using ACF custom blocks. The blocks themselves are working fine.
So currently I have the following in my functions.php file:

function my_allowed_block_types( $allowed_blocks, $post ) {
// works on all content
$allowed_blocks = array(
‘core/image’,
‘core/paragraph’,
‘core/heading’,
‘core/list’
);
// works for all pages but too general for what I want to do
if( $post->post_type === ‘page’ ) {
$allowed_blocks= array(
‘acf/homepage’
);
}
// Intended to restrict to just one block on my homepage template but does not
if ( is_page_template(‘page-home.php’) ) {
$allowed_blocks= array(
‘acf/homepage’
);
}

Read more here:: How to specify which Gutenberg blocks are available in the editor for a page template

Leave a Reply

Your email address will not be published. Required fields are marked *