How to use plugins with templates within Sage

Hello,

I have installed a new plugin (Eventin) which has its own post types and templates for the single view of the post types (speaker). Of course these templates are .php files and do not follow blade. As such, when navigating to the single-speaker view, all styles are lost and the header and footer do not load.

Is there a way to integrate third party plugin templates with Sage 10 so we do not lose styling or the header and footer?

Thank you

This is done with WooCommerce templates:

Thanks for the quick reply, but I am a little confused. This isn’t WooCommerce; would I create a different directory in my views folder for eventin? Or does the package work for all plugins?

Sage supports Blade-PHP (blade.php) templates.

That plugin has to use the WordPress template loading functions (wc_get_template_part/wc_get_template) or some other filters to override the template paths/content to the rendered PHP blade templates.

For WooCommerce this is also done:

You call that plugin “Eventin” - is that its official name? Where can it be found in the WordPress plugin directory?
When you mean the “The Events Calendar plugin”, this discussion shows what filters can be used to override the template paths:

Yes Eventin is its official name: https://themewinter.com/eventin/
It displays in the plugins directory as “wp-event-solution” and it uses the single_template hook within the add_action() function ( add_action(‘single_template’, [ $this, ‘speaker_single_template’ ] ); ) in order to override the template.

They also provide very specific documentation on how to override their default template by creating a new root directory within the theme: Speaker Template Override – Documentation for Plugins

The wc_get_template_part /wc_get_template functions you mentioned are WooCommerce specific. Even the way the package finds the templates is WooCommerce specific, so I’m still confused on how I can use the package you linked.

And I am not trying to override the template using a custom plugin. I am trying to integrate the templates provided by a plugin into Sage. I’ve used those methods before to upload my own templates, but that doesn’t work for what I am trying to do now.

But you want to use Blade files in the Sage theme instead just plain PHP files, right?
Because you want to include the header, footer and such? That’s what I understood.

I want to be able to integrate the templates into Sage. If I need to recreate them into blade, I will.

The add_filter(‘single_template’) method does not work.

add_filter('single_template', 'over_speaker_single_template');
function over_speaker_single_template( $single ) {
    global $post;

    if ( $post->post_type == 'etn-speaker' ) {
        if ( file_exists( get_theme_file_uri('/eventin/templates/single-speaker.blade.php') ) ){
            $single = get_theme_file_uri('/eventin/templates/single-speaker.blade.php');
        }
    }
    return $single;
}

I posted that in my functions file to try and redirect the template. I even tried to redirect to the blade file from the normal php file.

So the Sage Blade template doesn’t load when you use the code above?

For Sage 10 I use this invocation to get a template rendered to a string:

$output = \Roots\view('path/relative/to/views/directory/template-file')->render();

Correct, it does not load. And I just replaced my $single variable declaration with the line of code you provided with the render() and it still does not load the header or footer, or ANYTHING actually.

BUT when I do a wp_die($single); using the render() function you outlined above, it DOES return the blade file, and I know this because I wrote a sentence within the blade file to be able to identify it if it loads. The wp_die looks like this:

So it is loading the content from the blade file but nothing else, and it still does not actually load the template on the normal page, which looks like this:

So you use a filter like etn_single_speaker_template and let the filter handler function return the rendered HTML?
When you do that you get an empty/broken page instead? Are PHP errors/warnings logged? Maybe something goes wrong in the filter handler function, resulting in missing HTML at that point in the page.

Do you mean something like this? I have tried it, and it does nothing. It is weird, and there are no errors being logged. This is a baffling problem.

add_filter('single_template', 'over_speaker_single_template');
function over_speaker_single_template( $single ) {
    global $post;

    if ( $post->post_type == 'etn-speaker' ) {
        
            $single = \Roots\view(get_theme_file_path('/eventin/templates/single-speaker.blade.php'))->render();
        }
        return $single;
    }

Thank you for joining me on this journey

There is no need for using get_theme_file_path(...) when using \Roots\view(...)->render(),
just pass the path to that template file directly (and not as an absolute path (absolute path starting with /)):

add_filter('single_template', 'over_speaker_single_template');
function over_speaker_single_template( $single ) {
    global $post;

    if ( $post->post_type == 'etn-speaker' ) {
        $single = \Roots\view('eventin/templates/single-speaker.blade.php')->render();
    }
    return $single;
}