Smarty resource plugin that can read templates from database.
This plugin is inspired but similar from Xoops - resource.db.
To install and use this package, we recommend to use Composer:
composer require imponeer/smarty-db-resource
Otherwise, you need to include manually files from src/
directory.
If you want to use these extensions from this package in your project you need register them with registerResource
function from Smarty. For example:
$smarty = new \Smarty();
$plugin = new \Imponeer\Smarty\Extensions\DBResource\DBResource(
$pdo, // PDO compatible database connection
'default', // current template set name
'tplfile',
'tpl_source',
'tpl_lastmodified',
'tpl_tplset',
'tpl_file',
function (array $row): string { // function that converts database row info into string of real file
return $row['file'];
},
'default'
);
$smarty->registerResource($plugin->getName(), $plugin);
To use this resource from templates, you need to use db:
prefix when accessing files. For example :
{include file="db:/images/image.tpl"}
If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, try interactive GitHub tutorial.
If you found any bug or have some questions, use issues tab and write there your questions.