simsoft/twig
最新稳定版本:1.0.1
Composer 安装命令:
composer require simsoft/twig
包简介
A Twig wrapper, built for Twig template engine.
README 文档
README
A Twig wrapper, built for Twig template engine.
Install
composer require simsoft/twig
Basic Usage
Examples setup in bootstrap or entry script file.
<?php require "vendor/autoload.php"; use Simsoft\Twig\Twig; $twig = new Twig([ 'path' => 'path/to/templates', 'fileExtension' => '.twig', 'debug' => true, // default is false 'charset' => 'UTF-8', 'cache' => 'path/to/cache', 'timezone' => 'Asia/Kuala_Lumpur', 'extensions' => [new \App\MyExtension()], 'namespaces' => [ 'name' => '/path/to/template', 'layouts' => '/path/to/layouts', 'macros' => '/path/to/macros', 'components' => '/path/to/components', ], ]); $twig->display('template_name', ['name' => 'John']);
Building Extension
For further tutorial, please refer to Extending Twig.
<?php namespace App; use use Simsoft\Twig\Extension; class MyExtension extends Extension { public function getGlobals() : array { return [ 'guest_name' => 'John Doe', ]; } public function init(): void { // add filters $this->addFilter('obj_to_array', fn ($object) => (array)$object); // add functions $this->addFunction('dump', fn(...$args) => call_user_func_array('var_dump', $args)); // add test $this->addTest('red', function ($value) { if (isset($value->color) && $value->color == 'red') { return true; } if (isset($value->paint) && $value->paint == 'red') { return true; } return false; }); } }
Building Template files.
Please refer to Twig for Template Designers.
License
The Simsoft Validator is licensed under the MIT License. See the LICENSE file for details
统计信息
- 总下载量: 71
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-04