1. Go to this page and download the library: Download dalpras/smart-template 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/ */
dalpras / smart-template example snippets
/** ./mywebpage.php */
$templateEngine = new TemplateEngine(__DIR__ . '/templates');
echo $templateEngine->render('table.php', function ($render) {
return $render['table']([
'{class}' => 'text-right',
'{cols}' => $render['row'](['{text}' => 'hello datum!'])
]);
});
// or you can begin to nest everything you need
echo $templateEngine->render('table.php', function ($render) {
return $render['table']([
'{class}' => 'text-right',
'{rows}' => function($render) {
return $render['row'](['{text}' => 'hello nested!']);
},
]);
});
// or just use another file for rendering
echo $templateEngine->render('toolbar.php', function ($render) {
return $render['header']([
'{text}' => 'hello toolbar!'
]);
});
// also you can use many files as you want
echo $templateEngine->render('table.php', function ($render) {
return $render['table']([
'{class}' => 'text-right',
'{rows}' => function($render, TemplateEngine $template) {
return $template->render('toolbar.php', fn($render) => $render['header']([
'{text}' => 'hello different template toolbar'
]));
},
]);
});
// or custom specific functions for rendering
echo $templateEngine->render('table.php', function ($render) {
return $render['table']([
'{class}' => 'text-right',
'{rows}' => $render['myfunc']('hello func!'),
]);
});
// GREAT POWER INVOLVES GREAT RESPONSIBILITY!