According to https://developer.wordpress.org/block-editor/developers/block-api/block-templates/, I have managed to add a template to the custom post type with the following code -
/**
* Portfolio post template.
*/
function portfolio_post_template() {
$template = [
['template_path/block'],
];
$post_type_object = get_post_type_object( 'portfolio' );
$post_type_object->template = $template;
}
add_action( 'init', 'portfolio_post_template' );
Here comes the issue, I am trying to display different layout according to what user has selected in the layout dropdown under post attributes section, but the action hook is with init, there isn't any information about what post template has been selected at that point of time which allow me to set a condition to use different gutenberg template.
Is there other better hook to use instead of init? Or is there a different way to set gutenberg template while having the information of selected post template?