antidot-fw / twig-template-renderer
Antidot 框架 Twig 模板渲染库
0.2.0
2021-01-10 14:35 UTC
Requires
- php: ^7.4|^8.0
- antidot-fw/template-renderer: ^1.0
- psr/container: ^1.0
- twig/twig: ^3.0
Requires (Dev)
- phpstan/phpstan: ^0.12.25
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-08-30 01:43:52 UTC
README
Antidot 框架的 Twig 模板渲染器
安装
通过 Composer
$ composer require antidot-fw/twig-template-renderer
Antidot 框架
它将直接工作,你需要的只是将 TemplateRenderer 接口注入到你的请求处理程序构造函数中
作为独立组件
查看 src/Container
中的工厂类。
配置
<?php declare(strict_types=1); $config = [ 'template' => [ 'debug' => false, 'file_extension' => 'twig', 'charset' => 'utf-8', 'template_path' => 'templates', 'cache' => 'var/cache/twig', 'auto_reload' => false, 'autoescape' => 'html', 'strict_variables' => true, 'globals' => [ // 'name' => 'value', ], 'extensions' => [ // EtensionClassName::class, ], 'filters' => [ // 'name' => PHPCallableClass::class, // 'some_function' => 'php_some_function, ], 'functions' => [ // 'name' => PHPCallableClass::class, // 'some_function' => 'php_some_function, ], ], ];
用法
有关更详细的信息,请参阅完整的 Twig 文档。
在请求处理程序中
<?php declare(strict_types=1); use Antidot\Render\TemplateRenderer; use Laminas\Diactoros\Response\HtmlResponse; use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; class SomeHandler implements RequestHandlerInterface { private TemplateRenderer $template; public function __construct(TemplateRenderer $template) { $this->template = $template; } public function handle(ServerRequestInterface $request) : ResponseInterface { return new HtmlResponse( $this->template->render('index.html', [ 'name' => 'Koldo ;-D', ]) ); } }
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT 以获取详细信息。
安全
如果你发现任何安全问题,请通过电子邮件 kpicaza@example.com 而不是使用问题跟踪器。
鸣谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。