Easily include and pass data to theme overridable plugin templates.
This works generally the same way as the regular
WPDev\Template\Template helper, but with one key difference.
Instead of passing in just the filename of the template, an absolute path to the plugin's template file should be passed in. This is the file that will be used if there isn't an overriding template found in the child/parent themes.
To override a plugin's template file in your theme, the file must be located in
For example if the plugin you're overriding is in a folder called my-plugin, then it will look for templates in the child/parent theme's
templates/plugins/my-plugin/ folder. This is to help avoid template naming conflicts between plugins. It also has the benefit of keeping the templates folder organized.
use WPDev\Template\PluginTemplate; PluginTemplate::include(__DIR__.'/reusable-component.php'); // or with global function plugin_template(__DIR__.'/reusable-component.php');
use WPDev\Template\PluginTemplate; PluginTemplate::include(__DIR__.'/reusable-component.php', ['title' => 'So Easy']); // or with global function plugin_template(__DIR__.'/reusable-component.php', ['title' => 'So Easy']);
Locates and renders a theme template. Falls back to the absolute
For a more fluid syntax. Alternatively use
|Include a theme template file. Optionally pass data.|
|Locates a template file.|