covex-nn/twig-callable-bridge-bundle

此包已被 废弃,不再维护。没有建议的替代包。

提供简单的接口以扩展 Twig 的 PHP 函数

1.1.0 2016-07-08 07:58 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:34:44 UTC


README

Build Status SensioLabsInsight

此 Symfony2 扩展包旨在提供简单的接口以扩展 Twig 的 PHP 函数

安装

将依赖项添加到 composer.json

{
  "require" : {
    "covex-nn/twig-callable-bridge-bundle" : "~1.0"
  }
}

注册扩展包

AppKernel.php 文件中注册扩展包

// ...other bundles ...
$bundles[] = new Covex\TwigCallableBridgeBundle\CovexTwigCallableBridgeBundle();

配置

将配置添加到 config.yml

covex_twig_callable_bridge:
    functions:
        uppercase: strtoupper
    filters:
        lowercase: strtolower
    test:
        numeric: is_numeric

Twig

在 Twig 模板中使用您的函数、过滤器进行测试

{{ uppercase('qqq') }}
{{ 'WoW'|lowercase }}
{% if 1 is numeric %}yes{% else %}no{% endif %}