Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeroenboersma/php-template-bridge
https://github.com/jeroenboersma/php-template-bridge
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jeroenboersma/php-template-bridge
- Owner: JeroenBoersma
- License: mit
- Created: 2017-08-22T19:24:30.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-13T16:46:20.000Z (almost 7 years ago)
- Last Synced: 2024-05-20T03:44:50.077Z (6 months ago)
- Language: PHP
- Size: 43 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Template bridge
Template bridge between your legacy php code and newer template engines.
## Dependencies
Requires minimum of PHP 7.0. Also uses `srcoder/normalize-strings` for string manipulation.
## Engines
* Plain
* Twig
* Compatible## Basic usage
Use the manager to define your templates.
```php
use \Srcoder\TemplateBridge\Manager;
use \Srcoder\TemplateBridge\Engine\Twig;
use \Srcoder\TemplateBridge\Engine\Plain;// Initialize template bridge
$templateBridge = new Manager;
// or static
$templateBridge = Manager::instance();// Add a engine
$templateBridge->add(
'twig', // Name
new Twig(), // Template engine
300 // Prio, higher is more important
);$templateBridge->add(
'plain', // Name
new Plain(), // Template engine
600 // Prio, higher is more important
);// Adding a file
$templateManager->addFile('file');
// Will search for file.twig and file// Render template
echo $templateBridge->render();```
## Data
When rendering something you can add data to it.
```php
use \Srcoder\TemplateBridge\Data;echo $templateBridge->render(new Data(['key' => 'value']))
```## Fun part
### Twig engine
When a Twig file is found it will work exactly as you expect.
### Plain engine
Plain files will replace {{$variable}} from the Data object
Plain engine can also be used for javascript and html### Compatible engine