jdwx/web-twig 问题修复 & 功能扩展

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

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

jdwx/web-twig

最新稳定版本:v3.0.0

Composer 安装命令:

composer require jdwx/web-twig

包简介

Integrate twig templates with jdwx/web and jdwx/panels.

README 文档

README

A very thin module for integrating Twig templates into other web-related modules.

Installation

You can require it directly with Composer:

composer require jdwx/web-twig

Or download the source from GitHub: https://github.com/jdwx/web-twig.git

Requirements

This module requires PHP 8.3 and Twig 3.0 or later.

Usage

This module provides a simple interface for integrating Twig templates into panels and pages interfaces provided by the jdwx/panels and jdwx/web-php modules. The AbstractPage class can be subclassed to provide values when the template is rendered. The StaticPage class allows values to be provided when the page is instantiated. The MapPage class binds a Map that can be updated at any time.

You can also use subclasses to avoid repetitive code. For example, if you have all of your error page templates in one directory, you can create a subclass like this:

class ErrorPage extends StaticPage {


    /** @param array<string, mixed> $i_rValues */
    public function __construct( string $name, array $i_rValues = [] ) {
        # Give it the path to your error templates.
        $env = TwigHelper::forDirectory( __DIR__ . '/templates/' );
        parent::__construct( $env, $name, $i_rValues );
    }


    /** @param array<string, mixed> $i_rValues */
    public static function get( string $name, array $i_rValues = [] ) : string {
        return ( new self( $name, $i_rValues ) )->render();
    }


}

Then displaying errors is very straightforward:

echo ErrorPage::get( 'error404', [ 'return_url' => '/' ] ), "\n\n";

Stability

This module is relatively new and has not been extensively deployed in production yet, but the interface should be relatively stable. There's really not a lot to it; this module exists mainly to keep from introducing Twig as a dependency where it's not needed.

History

This module was loosely adapted from an existing codebase in early 2025.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-23