aatis/template-renderer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

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:

  • EXTENSION constant 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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-12-04