yiiext/twig-renderer
Composer 安装命令:
composer require yiiext/twig-renderer
包简介
Twig renderer for the Yii Framework.
关键字:
README 文档
README
This extension allows you to use Twig templates in Yii.
Resources
Requirements
- Yii 1.0 or above
Installation
Installing manually
- Extract the release file under
vendor/Twig. - Download and extract all Twig files from
fabpot-Twig-______.zip\fabpot-Twig-______\lib\Twig\underprotected/vendor/Twig. - Add the following to your config file 'components' section:
<?php 'viewRenderer' => array( 'class' => 'ext.ETwigViewRenderer', // All parameters below are optional, change them to your needs 'fileExtension' => '.twig', 'options' => array( 'autoescape' => true, ), 'extensions' => array( 'My_Twig_Extension', ), 'globals' => array( 'html' => 'CHtml' ), 'functions' => array( 'rot13' => 'str_rot13', ), 'filters' => array( 'jencode' => 'CJSON::encode', ), // Change template syntax to Smarty-like (not recommended) 'lexerOptions' => array( 'tag_comment' => array('{*', '*}'), 'tag_block' => array('{', '}'), 'tag_variable' => array('{$', '}') ), ),
Installing via Composer
- Get Composer
- Create file protected/composer.json if absent:
{
"repositories":[
{
"type":"package",
"package":{
"name":"yiiext/twig-renderer",
"version":"1.1.15",
"source":{
"type":"git",
"url":"https://github.com/yiiext/twig-renderer",
"reference":"v1.1.15"
}
}
}
],
"require":{
"php":">=5.3.0",
"yiisoft/yii": "dev-master",
"twig/twig": "1.*",
"yiiext/twig-renderer":"1.1.*"
}
}
- Run
composer updatein the protected folder of your app. - Add the following to your config file 'components' section:
<?php 'viewRenderer' => array( 'class' => 'application.vendor.yiiext.twig-renderer.ETwigViewRenderer', 'twigPathAlias' => 'application.vendor.twig.twig.lib.Twig', // All parameters below are optional, change them to your needs 'fileExtension' => '.twig', 'options' => array( 'autoescape' => true, ), 'extensions' => array( 'My_Twig_Extension', ), 'globals' => array( 'html' => 'CHtml' ), 'functions' => array( 'rot13' => 'str_rot13', ), 'filters' => array( 'jencode' => 'CJSON::encode', ), // Change template syntax to Smarty-like (not recommended) 'lexerOptions' => array( 'tag_comment' => array('{*', '*}'), 'tag_block' => array('{', '}'), 'tag_variable' => array('{$', '}') ), ),
Usage
- See Twig syntax.
- Current controller properties are accessible via {{this.pageTitle}}.
- Yii::app() object is accessible via {{App}}.
- Yii's core static classes (for example, CHtml) are accessible via {{C.ClassNameWithoutFirstC.Method}} (example: {{C.Html.textField(name,'value')}})
- To call functions or methods which return non-string result wrap these calls with 'void' function: {{void(App.clientScript.registerScriptFile(...))}}
Widgets usage example
<div id="mainmenu"> {{ this.widget('zii.widgets.CMenu',{ 'items':[ {'label':'Home', 'url':['/site/index']}, {'label':'About', 'url':{0:'/site/page', 'view':'about'} }, {'label':'Contact', 'url':['/site/contact']}, {'label':'Login', 'url':['/site/login'], 'visible':App.user.isGuest}, {'label':'Logout ('~App.user.name~')', 'url':['/site/logout'], 'visible':not App.user.isGuest} ] }, true) }} </div><!-- mainmenu -->
yiiext/twig-renderer 适用场景与选型建议
yiiext/twig-renderer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 81.9k 次下载、GitHub Stars 达 70, 最近一次更新时间为 2013 年 12 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「twig」 「extension」 「renderer」 「yii」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yiiext/twig-renderer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yiiext/twig-renderer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yiiext/twig-renderer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
A custom URL rule class for Yii 2 which allows to create translated URL rules
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
统计信息
- 总下载量: 81.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 70
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2013-12-17