1. Go to this page and download the library: Download unprefix/template-loader library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
unprefix / template-loader example snippets
$loader = new TemplateLoader\Loader('template_slug', new TemplateLoader\DataStorage());
$loader->withData(new ModelInterface())
->usingTemplate('/relative/file/path.php')
->render()
$loader = new TemplateLoader\Loader('template_slug', new TemplateLoader\DataStorage());
$loader->withData(new ModelInterface())
->usingTemplate('/relative/file/path.php')
->butFallbackToTemplate('/plugin/relative/file/path.php')
->render();
add_filter('tmploader_template_engine_data', function(TemplateLoader\ModelInterface $data, string $slug) {
switch($slug) {
case 'my_slug':
// Do something
break;
default:
break;
}
return $data;
});
add_filter('tmploader_template_engine_data_my_template', function(TemplateLoader\ModelInterface $data) {
return new DataTemplate(); // An new instance of a class implementing TemplateLoader\ModelInterface.
});
$loader = new TemplateLoader\Loader('template_slug', new TemplateLoader\DataStorage());
$loader->withData(new ModelInterface())
->usingTemplate('/relative/file/path.php')
->butFallbackToTemplate('/plugin/relative/file/path.php')
->render();
// Some code ... and then ...
$loader->withData(new ModelInterface())
->render();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.