imponeer/smarty-db-resource

Smarty plugin that adds DB resource type

v3.0.6 2023-09-04 20:29 UTC

README

License GitHub release Maintainability PHP Packagist

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.