pug/twig
Composer 安装命令:
composer require pug/twig
包简介
Compile Pug templates into Twig templates
README 文档
README
This package can convert basic pug codes into Twig code. Caution, this package should not be used to handle Pug templates in Symfony, the right way to do it is to use pug-symfony and to either polyfill Twig expressions only or delegate expression handle to the Twig code parser.
This package can help you moving from Pug to Twig by generating equivalent code or can be used to create a Pug input interface to insert Twig templates in an existing application. These are the only kind of business you should handle with this package.
For a full-featured Pug template engine in Symfony pug-symfony is what you need. If you miss a feature, ask in the issues, there probably already exists a way to do the same, else we'll try to add it.
Instalation
First install composer if you have not: https://getcomposer.org/
Then run the following command:
composer require pug/twig
Or if you installed composer locally:
php composer.phar require pug/twig
Extension for Phug/Pug-php to output Twig (PHP pug to twig converter)
my-pug-input.pug:
ul#users - for user in users li.user // comment = user.name | Email: #{user.email} a(href=user.url) Home page
index.php:
include 'vendor/autoload.php'; echo PugToTwig::convert(file_get_contents('my-pug-input.pug'));
Will output:
<ul id="users"> {% for user in users %} <li class="user"> {# comment #} {{ user.name | e }} Email: {{ user.email | e }} <a href="{{ user.url | e }}">Home page</a> </li> {% endfor %} </ul>
(indentation not guaranteed).
Some features such as mixins could output PHP that you would need to evaluate:
$html = eval('?>' . PugToTwig::convert($pugCode));
Warning: you should be sure you don't let user input appears
between <?php and ?>. It should not happen easily because
expressions and codes are turned into Twig code that the
PHP eval will just ignore, but be careful.
Not supported features:
- Mixins with dynamic names
- Mixins arguments: de facto, argument display will become Twig interpolation and Twig can't handle pug mixins, so mixins are evaluated before Twig will evaluate code/expressions.
pug/twig 适用场景与选型建议
pug/twig 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 623 次下载、GitHub Stars 达 11, 最近一次更新时间为 2017 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「php」 「twig」 「html」 「jade」 「pug」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pug/twig 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pug/twig 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pug/twig 相关的其它包
同方向 / 同关键字的高下载量 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).
The bundle for easy using json-rpc api on your project
Twig extensions for Tracy Debugger
统计信息
- 总下载量: 623
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-29