danilovl/apply-filter-twig-extension-bundle

Symfony twig 扩展包提供在模板中的动态调用过滤器。

v3.2.2 2024-03-30 07:44 UTC

This package is auto-updated.

Last update: 2024-09-30 09:09:04 UTC


README

phpunit downloads latest Stable Version license

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 许可证 授权。