srcoder / template-bridge
Template bridge between your legacy and other template engines
1.0.2
2017-12-13 16:45 UTC
Requires
- php: ~7.0
- srcoder/normalize-strings: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6.5
Suggests
- erusev/parsedown: If you want to use the Markdown syntax. Version 1.6 is tested.
- twig/twig: If you want to use the Twig implementation. Version 2.4 is tested.
README
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.
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.
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