danilovl / apply-filter-twig-extension-bundle
Symfony twig 扩展包提供在模板中的动态调用过滤器。
v3.2.2
2024-03-30 07:44 UTC
Requires
- php: ^8.3
- symfony/framework-bundle: ^7.0
- symfony/twig-bundle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^10.2
README
ApplyFilterTwigExtensionBundle
关于
Symfony twig 扩展包提供在模板中的动态调用过滤器。
要求
- PHP 8.3 或更高版本
- Symfony 7.0 或更高版本
1. 安装
使用 Composer 安装 danilovl/apply-filter-twig-extension-bundle
包
composer require danilovl/apply-filter-twig-extension-bundle
如果未自动添加,将 ApplyFilterTwigExtensionBundle
添加到您的应用程序包中
<?php // config/bundles.php return [ // ... Danilovl\ApplyFilterTwigExtensionBundle\ApplyFilterTwigExtensionBundle::class => ['all' => true] ];
2.0 使用方法
在 twig 模板中使用 apply_filter
函数。
{{ apply_filter('max', {2: "e", 1: "a", 3: "b", 5: "d", 4: "c"}) }}
或
{% set filterName = 'upper' %} {% if isToLower is defined and isToLower %} {% set filterName = 'lower' %} {% endif %} {{ apply_filter(filterName, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.') }}
更多示例在 tests
目录中。
许可证
ApplyFilterTwigExtensionBundle 是开源软件,根据 MIT 许可证 授权。