https://github.com/imponeer/smarty-db-resource
Smarty plugin that adds DB resource type
https://github.com/imponeer/smarty-db-resource
hacktoberfest resource smarty smarty-plugins
Last synced: about 2 months ago
JSON representation
Smarty plugin that adds DB resource type
- Host: GitHub
- URL: https://github.com/imponeer/smarty-db-resource
- Owner: imponeer
- License: mit
- Created: 2021-02-07T09:59:03.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-08T20:13:06.000Z (11 months ago)
- Last Synced: 2024-08-09T13:43:35.519Z (10 months ago)
- Topics: hacktoberfest, resource, smarty, smarty-plugins
- Language: PHP
- Homepage:
- Size: 66.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](LICENSE)
[](https://github.com/imponeer/smarty-db-resource/releases) [](https://codeclimate.com/github/imponeer/smarty-db-resource/maintainability) [](http://php.net)
[](https://packagist.org/packages/imponeer/smarty-db-resource)# Smarty DB resource
[Smarty](https://smarty.net) resource plugin that can read templates from database.
This plugin is inspired but similar from [Xoops](https://xoops.org) - [resource.db](https://github.com/XOOPS/XoopsCore25/blob/v2.5.8/htdocs/class/smarty/xoops_plugins/resource.db.php).
## Installation
To install and use this package, we recommend to use [Composer](https://getcomposer.org):
```bash
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](https://www.smarty.net/docs/en/api.register.resource.tpl) from [Smarty](https://www.smarty.net). For example:
```php
$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 :
```smarty
{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](https://skills.github.com).
If you found any bug or have some questions, use [issues tab](https://github.com/imponeer/smarty-db-resource/issues) and write there your questions.