title: How can I enqueue script based on template part?
body: <p>I want to be able to load scripts and stylesheets in the head and foot based on wordpress get template part</p>
  
  <h3>I have on in my front-page.php the following code:</h3>
  
  <pre><code>&lt;?php 
  /*
  Template Name: Home Page
  */
  
  get_header();
  
  $loop = new WP_Query( array( 'post_type' =&gt; 'home_page','posts_per_page'=&gt;1, 'orderby' =&gt; 'menu_order', 'order' =&gt; 'DESC') ); 
  while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); 
  
  if( get_field('home_page_template_type') == 'Bookcase') {
  
      get_template_part( 'bookcase' ); 
  
  }elseif (get_field('home_page_template_type') == 'Bookers') {
  
      get_template_part('bookers' ); 
  
  }
  
  endwhile;
  
  get_footer();
  </code></pre>
  
  <h3>Now in my functions php I want to do this</h3>
  
  <pre><code>// Register Script
  if (!function_exists('theme_scripts')) {
      function villarosa_theme_scripts() {
          global $wp_scripts;
  
          if ('bookcase.php') {
              // Load our main stylesheet.
              wp_deregister_style( 'bookcase-styles' );
              wp_register_style( 'bookcase-styles',trailingslashit( THEME_URI ) .'bookcase/css/style.css', false, '1.0' );
              wp_enqueue_style( 'bookcase-styles' );
  
              // jQuery (necessary for Bootstrap's JavaScript plugins) 
              wp_deregister_script( 'jquery' );
              wp_register_script( 'jquery', trailingslashit( THEME_URI ) .'bookcase/js/jquery.js', false, '1.0', true );
              wp_enqueue_script( 'jquery' );
  
              wp_deregister_script( 'jquery-migrate' );
              wp_register_script( 'jquery-migrate', trailingslashit( THEME_URI ) .'bookcase/js/jquery-migrate-1.2.1.js', false, '1.0', true );
              wp_enqueue_script( 'jquery-migrate' );
  
              wp_deregister_script( 'jquery-easing' );
              wp_register_script( 'jquery-easing', trailingslashit( THEME_URI ) .'bookcase/js/jquery.easing.1.3.js', false, '1.0', true );
              wp_enqueue_script( 'jquery-easing' );
  
              wp_deregister_script( 'script' );
              wp_register_script( 'script', trailingslashit( THEME_URI ) .'bookcase/js/script.js', false, '1.0', true );
              wp_enqueue_script( 'script' );
  
              wp_deregister_script( 'jquery-equalheights' );
              wp_register_script( 'jquery-equalheights', trailingslashit( THEME_URI ) .'bookcase/js/jquery.equalheights.js', false, '1.0', true );
              wp_enqueue_script( 'jquery-equalheights' );
  
              wp_deregister_script( 'jquery-ui-totop' );
              wp_register_script( 'jquery-ui-totop', trailingslashit( THEME_URI ) .'bookcase/js/jquery.ui.totop.js', false, '1.0', true );
              wp_enqueue_script( 'jquery-ui-totop' );
  
              wp_deregister_script( 'superfish' );
              wp_register_script( 'superfish', trailingslashit( THEME_URI ) .'bookcase/js/superfish.js', false, '1.0', true );
              wp_enqueue_script( 'superfish' );
  
              wp_deregister_script( 'jquery-mobilemenu' );
              wp_register_script( 'jquery-mobilemenu', trailingslashit( THEME_URI ) .'bookcase/js/jquery.mobilemenu.js', false, '1.0', true );
              wp_enqueue_script( 'jquery-mobilemenu' );
  
              wp_deregister_script( 'sForm' );
              wp_register_script( 'sForm', trailingslashit( THEME_URI ) .'bookcase/js/sForm.js', false, '1.0', true );
              wp_enqueue_script( 'sForm' );
  
          } else if ('bookers.php') {
              // Load our main stylesheet.
              wp_deregister_style( 'bookers-styles' );
              wp_register_style( 'bookers-styles',trailingslashit( THEME_URI ) .'bookers/css/style.css', false, '1.0' );
              wp_enqueue_style( 'bookers-styles' );
  
              wp_deregister_style( 'stuck' );
              wp_register_style( 'stuck',trailingslashit( THEME_URI ) .'bookers/css/stuck.css', false, '1.0' );
              wp_enqueue_style( 'stuck' );
  
              // jQuery (necessary for Bootstrap's JavaScript plugins) 
              wp_deregister_script( 'jquery' );
              wp_register_script( 'jquery', trailingslashit( THEME_URI ) .'bookers/js/jquery.js', false, '1.0', true );
              wp_enqueue_script( 'jquery' );
  
              wp_deregister_script( 'jquery-migrate' );
              wp_register_script( 'jquery-migrate', trailingslashit( THEME_URI ) .'bookers/js/jquery-migrate-1.2.1.js', false, '1.0', true );
              wp_enqueue_script( 'jquery-migrate' );
  
              wp_deregister_script( 'jquery-easing' );
              wp_register_script( 'jquery-easing', trailingslashit( THEME_URI ) .'bookers/js/jquery.easing.1.3.js', false, '1.0', true );
              wp_enqueue_script( 'jquery-easing' );
  
              wp_deregister_script( 'script' );
              wp_register_script( 'script', trailingslashit( THEME_URI ) .'bookers/js/script.js', false, '1.0', true );
              wp_enqueue_script( 'script' );
  
              wp_deregister_script( 'jquery-equalheights' );
              wp_register_script( 'jquery-equalheights', trailingslashit( THEME_URI ) .'bookers/js/jquery.equalheights.js', false, '1.0', true );
              wp_enqueue_script( 'jquery-equalheights' );
  
              wp_deregister_script( 'jquery-ui-totop' );
              wp_register_script( 'jquery-ui-totop', trailingslashit( THEME_URI ) .'bookers/js/jquery.ui.totop.js', false, '1.0', true );
              wp_enqueue_script( 'jquery-ui-totop' );
  
              wp_deregister_script( 'superfish' );
              wp_register_script( 'superfish', trailingslashit( THEME_URI ) .'bookers/js/superfish.js', false, '1.0', true );
              wp_enqueue_script( 'superfish' );
  
              wp_deregister_script( 'tmStickUp' );
              wp_register_script( 'tmStickUp', trailingslashit( THEME_URI ) .'bookers/js/tmStickUp.js', false, '1.0', true );
              wp_enqueue_script( 'tmStickUp' );
  
              wp_deregister_script( 'jquery-mobilemenu' );
              wp_register_script( 'jquery-mobilemenu', trailingslashit( THEME_URI ) .'bookers/js/jquery.mobilemenu.js', false, '1.0', true );
              wp_enqueue_script( 'jquery-mobilemenu' );
          }
      }
  }
  </code></pre>
  
  <p>However the scripts are loading for my first condition but for else if they are not? Why is this the case? </p>