Plugin Template not being overwritten in Sage 9

I’m using Sage 9. I have read through the documentation for Sage 9 many times now, as well as begun Laravel and Blade training through Laracasts. But am experiencing an issue where I cannot override a Theme Template that is being used by a Plugin.

I have a Plugin installed called ‘WP Hotel Booking’ and it states I can override the Single Room template by placing it in sage/tp-hotel-booking/single-room.php

I have tried this, also tried moving it into resources/views/ and also tried renaming it to single-room.blade.php and putting only <h1>Test</h1> in the file contents. It remains completely ignored.

I am unable to decipher whether this is a problem with the Plugin or related to Blade somehow. Can anyone explain how you go about identifying this?

Hey @s3w47m88 - out of the box, the file resources/wp-hotel-booking/single-room.php should override the plugin template.

To get it more neatly integrated into the Sage file organization and Blade, add this to app/filters.php:

add_filter('template_include', function ($template) {
    if (is_single() && get_post_type() == 'hb_room') {
        $blade_template = locate_template('single-room.blade.php');

        return ($blade_template) ? $blade_template : $template;
    }

    return $template;
}, 100);

And put your custom template in resources/views/single-room.blade.php.

You can modify that filter as needed if you want to use a different folder or change anything else.

Same approach should work for the plugin’s other templates if you want to override more.

I’m following this solution to Theme My Login plugin templates.

I start converting file to blade format but I stop in an error:

The original:

<div class="tml tml-login" id="theme-my-login<?php $template->the_instance(); ?>">
	<?php $template->the_action_template_message( 'login' ); ?>
	<?php $template->the_errors(); ?>

Blade format:

<div class="tml tml-login" id="theme-my-login@php $template->the_instance() @endphp">
	@php $template->the_action_template_message( 'login' ) @endphp
	@php $template->the_errors() @endphp

Error:

Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function the_action_template_message() on null in /srv/www/website/public_html/wp-content/uploads/cache/00f3f37a810a747360a78716d6edd577d9db6c08.php:3

Sorry @marcelo2605, didn’t see your question until now.

In theory, where is $template being set? That error indicates that it’s not defined (it’s null).

No problem @mmirus. I fixed the problem adding a theme-my-login folder inside resources folder. Inside, I add the TML templates files.

Found this solution here: https://wordpress.org/support/topic/custom-login-template-with-sage-9-theme/

That was the best and short explanation about overwritte templates files in Sage 9.