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?
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?
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.
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.
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.
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;
}