When I build feature plugins for my sites I like to include views with them so I’m not creating too many interdependencies between my theme and plugins.
In the past I’ve used Gamajo Template Loader to let the plugin keep its own views, and let the theme override them, like WooCommerce and other plugins do.
But this method doesn’t work with Blade templates because Sage’s blade functionality isn’t called when Gamajo does its magic.
A solution to this would be to allow Sage’s Blade implementation to accept a path to look for views in the plugin directory. It would check the theme first for an override, and fall back to the plugin path.
It would be easy enough to check for Blade functionality in the plugin before including a view, and besides that I’m much more comfortable having a plugin require Sage9 (any Sage9) than I am requiring specific template files within that Sage9 theme.
So what do you think? Is this possible now? Is it a good feature suggestion if not?
@MWDelaney - Could you share an example of what that might look like? I’m creating some functionality and would like to load a blade template from a specific directory that is not the standard view directory.
Using the code below works great to render a template from the standard directory, but how to I have it look in a custom directory? Ideally allowing for someone to override these in their own theme directory.
this works fine. however, if I add a new template to the partials directory it says it cannot find the template. I’ve cleared the cache as well. seems very strange as I can include the new partial directly from another template via @include
You’d have to be absolutely sure that the theme was Sage-based, but you should be able to do something like this:
// Set up the template file we want to include
$template = plugin_dir_path(__FILE__) . "views/shortcode";
// Set up template data if/as necessary
$data = apply_filters('sage/template/app-data/data', );
// return the populated template using Sage’s built-in template() function
return \App\template($template, $data);
This almost definitely won’t work out of the box (I’m typing this from a phone) but it might get you moving in the right direction. Hopefully in the future Clover will help ease some of these difficulties.