定制 phpnomad/twig-integration 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

phpnomad/twig-integration

最新稳定版本:1.0.1

Composer 安装命令:

composer require phpnomad/twig-integration

包简介

README 文档

README

Latest Version Total Downloads PHP Version License

Integrates Twig with PHPNomad's template strategy. It implements phpnomad/template's CanRender interface on top of Twig 3, so any code in your application that depends on CanRender can render .twig files without knowing Twig is doing the work. This is the default templating integration for PHPNomad applications that run outside WordPress.

Installation

composer require phpnomad/twig-integration

What this provides

  • TwigEngine, a CanRender implementation that loads templates through Twig's Environment and FilesystemLoader and auto-appends .twig to the template path you pass in.
  • TwigConfigProvider, an interface your application implements to tell the engine where its template directory lives.
  • Exception mapping so a missing template surfaces as TemplateNotFound and any other render failure surfaces as TemplateException, both from phpnomad/template.

Requirements

  • PHP 8.0 or later (inherited from twig/twig ^3.0)
  • phpnomad/template ^1.0
  • twig/twig ^3.0

Usage

Implement TwigConfigProvider to point at your templates directory, then bind TwigEngine to CanRender in your bootstrapper's class definitions.

<?php

namespace MyApp\Templates;

use PHPNomad\Twig\Integration\Interfaces\TwigConfigProvider;

class TemplateConfig implements TwigConfigProvider
{
    public function getTemplateDirectory(): string
    {
        return __DIR__ . '/templates';
    }
}
<?php

namespace MyApp;

use MyApp\Templates\TemplateConfig;
use PHPNomad\Loader\Interfaces\HasClassDefinitions;
use PHPNomad\Template\Interfaces\CanRender;
use PHPNomad\Twig\Integration\Interfaces\TwigConfigProvider;
use PHPNomad\Twig\Integration\Strategies\TwigEngine;

class TemplateInitializer implements HasClassDefinitions
{
    public function getClassDefinitions(): array
    {
        return [
            TwigEngine::class => CanRender::class,
            TemplateConfig::class => TwigConfigProvider::class,
        ];
    }
}

With those bindings in place, anywhere CanRender is injected you can call $template->render('emails/welcome', ['name' => $user->name]) and the engine will resolve templates/emails/welcome.twig.

Documentation

License

MIT. See LICENSE.txt.

统计信息

  • 总下载量: 43
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固