aatis/template-renderer
最新稳定版本:1.3.0
Composer 安装命令:
composer require aatis/template-renderer
包简介
Template renderer of Aatis
README 文档
README
Installation
composer require aatis/template-renderer
Dependencies
twig/twigaatis/dependency-injection(https://github.com/BatMaxou/aatis-dependency-injection)aatis/stacking-service(https://github.com/BatMaxou/aatis-stacking-service)
Usage
Requirements
Add the TemplateRenderer service into the Container.
# In config/services.yaml file : include_services: - 'Aatis\TemplateRenderer\Service\TemplateRenderer'
// Directly in PHP code when building the container : (new ContainerBuilder($ctx)) ->register(TemplateRenderer::class) ->build();
Basic usage
Call render() method with template path and an optionnal array of data.
$templateRenderer->render('path/to/template', [ 'var_name' => 'value' ]);
Custom Template Renderer
By default, this template renderer supports .html, .tpl.php and .html.twig files.
You can add your own template renderer by creating a class that extends AbstractTemplateRenderer.
This Custom Template Renderer must contains:
EXTENSIONconstant calling the case of the enum corresponding to the target extension.render()method that will be called by the base template renderer.
class ExtraRenderer extends AbstractTemplateRenderer { public const EXTENSION = '.tpl.extra'; public function render(string $template, array $vars = []): string { // Transform the special extension type template into a string } }
If needed, you can use the getTemplateContent() method of the AbstractTemplateRenderer to extract the vars and get the content of the template which will be rendered.
class ExtraRenderer extends AbstractTemplateRenderer { public const EXTENSION = '.tpl.extra'; public function render(string $template, array $vars = []): string { // do some stuff $content = $this->getTemplateContent($template, $vars); // do some stuff and return the content } }
统计信息
- 总下载量: 181
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2023-12-04