How can I insert a template into base.php when using a custom rewrite rule?

I am creating a custom rewrite rule so I can implement a postcode search of a CPT. I have manged to insert a custom template but it outputs in the Head currently. I tried including a new base-custom.php but it just loads base.php. Do I need to filter SageWrapping somehow?

class Experts {

	public function __construct() {
		add_action( 'init', array( $this, 'expert_routes' ) );
		add_filter( 'query_vars', array( $this, 'manage_expert_routes_query_vars') );
		add_action( 'template_redirect', array( $this, 'front_controller' ) );
		add_action( 'before_expert_postcode_search', array( $this, 'expert_postcode_search_results' ) );

	public function expert_routes() {
		add_rewrite_rule( '^expert/([^/]+)/?', 'index.php?control_action=$matches[1]', 'top' );

	public function manage_expert_routes_query_vars( $query_vars ) {
		$query_vars[] = 'control_action';
		return $query_vars;

	public function front_controller() {

		global $wp_query;
		$control_action = isset ( $wp_query->query_vars['control_action'] ) ? $wp_query->query_vars['control_action'] : '';
		switch ( $control_action ) {
			case 'search':
				do_action( 'before_expert_postcode_search' );

	public function expert_postcode_search_results(){
		get_template_part('templates/content-experts-search'); // Loads in HEAD
		//include('base-template-expert-search.php'); // Just loads base.php


From context cues I’m guessing you’re using Sage 8. If you were in Sage 9 I would recommend a @stack (see details here). With 8 you could probably get away with a conditional and get_post_type.

@MWDelaney I’m assuming you mean a conditional check in base.php around

include Wrapper\template_path();

That didn’t sound quite what I was after but I have come up with the following options.

  1. Change the Template before Sage hook into this.

add_filter('template_include', [__NAMESPACE__ . '\\SageWrapping', 'wrap'], 109);

add_filter( 'template_include', array( $this, 'sz_change_inserted_template' ), 99 );
public function sz_change_inserted_template( $template ) {
	return get_template_directory() . '\templates\content-experts-search.php';
  1. Use the filer in SageWrapper to change the base wrapper.

add_filter('sage/wrap_base', array( $this, 'sz_swap_base_template'));

public function sz_swap_base_template($templates) {
	array_unshift($templates, 'base-template-expert-search.php'); // Shift the template to the front of the array
	return $templates; // Return our modified array with base-$cpt.php at the front of the queue

I actually just meant doing this in base.php:

if('the-post-type' == get_post_type()) {