tangoman / twig-helper-bundle
该包最新版本(1.0.2)没有提供许可证信息。
Symfony TwigHelper Twig 扩展包
1.0.2
2018-04-08 21:21 UTC
Requires
- php: >=5.4.0
- twig/twig: ~1.12|~2
This package is auto-updated.
Last update: 2024-09-05 03:47:15 UTC
README
TangoMan TwigHelper Bundle 提供了一系列有用的 Twig 函数。
安装
步骤 1:下载 Bundle
打开命令行,进入项目目录,执行以下命令以下载此 Bundle 的最新稳定版本
$ composer require tangoman/twig-helper-bundle
此命令需要您全局安装了 Composer,如 Composer 文档中的安装章节所述。
步骤 2:启用 Bundle
然后,通过将其添加到项目 app/AppKernel.php
文件中注册的 Bundle 列表来启用该 Bundle
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { // ... public function registerBundles() { $bundles = array( // ... new TangoMan\TwigHelperBundle\TangoManTwigHelperBundle(), ); // ... } }
可用函数
start_with
(已弃用,因为 twig 3x 可以很好地处理这个)
检查 haystack 中的至少一个元素是否以 needle 开头。
{% if start_with(app.request.attributes.get('_route'), item.pages ?? []) %} {{ item }} {% endif %}
end_with
(已弃用,因为 twig 3x 可以很好地处理这个)
检查 haystack 中的至少一个元素是否以 needle 结尾。
{% if end_with(app.request.attributes.get('_route'), ['index','list']) %} {{ item }} {% endif %}
is_numeric
查找变量是否为数字或数字字符串。
{% if is_numeric(item) %} {{ item }} {% else %} "{{ item }}" {% endif %}
is_string
查找变量的类型是否为字符串。
{% if is_string(user) %} Welcome {{ user }} ! {% else %} Are you kidding me ? Is "{{ user }}" even a name ? {% endif %}
可用过滤器
to_array
将 stdObject 或 json 字符串转换为可遍历数组。
{% for key, value in object|to_array %} <td>{{ key }}</td> <td>{{ value }}</td> {% endif %}
注意
如果您发现任何错误,请在此处报告:问题
许可证
版权(c)2020 Matthias Morin
如果您喜欢 TangoMan TwigHelper Bundle,请给它加星!并在 GitHub 上关注我:TangoMan75 ... 并查看我的其他有趣项目。