imponeer / smarty-db-resource
Smarty plugin that adds DB resource type
Installs: 19 651
Dependents: 1
Suggesters: 1
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.3|^8.0
- ext-pdo: *
- imponeer/smarty-extensions-contracts: ^3.0
Requires (Dev)
- ext-sqlite3: *
- phpunit/phpunit: ^8.0 || ^9.0
README
Smarty DB resource
Smarty resource plugin that can read templates from database.
This plugin is inspired but similar from Xoops - resource.db.
Installation
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.
Registering in Smarty
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);
Using from templates
To use this resource from templates, you need to use db:
prefix when accessing files. For example :
{include file="db:/images/image.tpl"}
How to contribute?
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.