JavaScript for WordPress Forums Gutenberg Development Adding Block Templates to a Page Template? Reply To: Adding Block Templates to a Page Template?

#55872
GPorter43
Participant

I have tried similar with some php, in functions.php


add_action('wp_enqueue_scripts','Load_BlockTemplate');
function Load_BlockTemplate(){
    if ( is_page_template('custom-page.php') ) {
        wp_enqueue_script('BlockTemplate-script', 'path/to/script.js');
    } 
}

The problem i found was that when you create the new page its default until you publish and then when you edit the page all templates are present.
Would love to know how to do this in js so it is dynamic and more user friendly