zf-commons/zfc-twig
Composer 安装命令:
composer require zf-commons/zfc-twig
包简介
Zend Framework 2 Module that provides a Twig rendering strategy and extensions to render actions or trigger events from your templates
README 文档
README
ZfcTwig is a module that integrates the Twig templating engine with Zend Framework 2.
Installation
- Add
"zf-commons/zfc-twig": "dev-master"to yourcomposer.jsonfile and runphp composer.phar update. - Add
ZfcTwigto yourconfig/application.config.phpfile under themoduleskey.
Configuration
ZfcTwig has sane defaults out of the box but offers optional configuration via the zfctwig configuration key. For
detailed information on all available options see the module config file
class.
Documentation
Setting up Twig extensions
Extensions can be registered with Twig by adding the FQCN to the extensions configuration key which is exactly how the
ZfcTwig extension is registered.
// in module configuration or autoload override return array( 'zfctwig' => array( 'extensions' => array( // an extension that uses no key 'My\Custom\Extension', // an extension with a key so that you can remove it from another module 'my_custom_extension' => 'My\Custom\Extension' ) ) );
Configuring Twig loaders
By default, ZfcTwig uses a Twig_Loader_Chain so that loaders can be chained together. A convenient default is setup using
a filesystem loader with the path set to
module/Application/view which should work out of the box for most instances. If you wish to add additional loaders
to the chain you can register them by adding the service manager alias to the loaders configuration key.
// in module configuration or autoload override return array( 'zfctwig' => array( 'loaders' => array( 'MyTwigFilesystemLoader' ) ) ); // in some module public function getServiceConfiguration() { return array( 'factories' => array( 'MyTwigFilesystemLoader' => function($sm) { return new \Twig_Loader_Filesystem('my/custom/twig/path'); } ) ); }
Using ZF2 View Helpers
Using ZF2 view helpers is supported through the ZfcTwig\Twig\FallbackFunction function.
{# Simple view helper echo #} {{ docType() }} {# Echo with additional methods #} {{ headTitle('My Company').setSeparator('-') }} {# Using a view helper without an echo #} {% do headTitle().setSeparator('-') %} {# Combining view helpers #} {% set url = ( url('my/custom/route') ) %}
Examples
Example .twig files for the skeleton application can be found in the examples folder.
Gotchas
ZF2 does not support multiple renderers with view helpers very well. As a workaround, ZfcTwig registers its own
HelperPluginManager that extends the default Zend\View\HelperPluginManager and adds the default as a peering manager.
This let's ZfcTwig register its own renderer with view helpers that require it and fallback to the default manager for
view helpers that do not require one.
As a caveat, you must register view helpers that require a renderer with ZfcTwig. An example can be seen in
config/module.config.php where the HelperConfig for the default navigation helpers is registered with ZfcTwig.
zf-commons/zfc-twig 适用场景与选型建议
zf-commons/zfc-twig 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 579.04k 次下载、GitHub Stars 达 93, 最近一次更新时间为 2012 年 05 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「twig」 「zf2」 「module」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zf-commons/zfc-twig 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zf-commons/zfc-twig 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zf-commons/zfc-twig 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
LosLog provides some log utility
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).
EdpModuleLayouts is very simple Laminas module for making module-specific layouts insanely easy.
统计信息
- 总下载量: 579.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 93
- 点击次数: 27
- 依赖项目数: 15
- 推荐数: 1
其他信息
- 授权协议: Unknown
- 更新时间: 2012-05-25