srcoder / template-bridge
在您的旧模板引擎与其他模板引擎之间建立桥梁
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
在您的旧 PHP 代码和新版模板引擎之间建立桥梁。
依赖项
需要至少 PHP 7.0。还使用 srcoder/normalize-strings
进行字符串操作。
引擎
- 纯模板
- Twig
- 兼容
基本用法
使用管理器定义您的模板。
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();
数据
在渲染内容时,您可以向其添加数据。
use \Srcoder\TemplateBridge\Data; echo $templateBridge->render(new Data(['key' => 'value']))
有趣的部分
Twig 引擎
当找到 Twig 文件时,它将按您预期的方式工作。
纯模板引擎
纯模板文件将替换数据对象中的 {{$variable}}。纯模板引擎也可以用于 JavaScript 和 HTML。