covex-nn/twig-callable-bridge-bundle

Provides a simple interface to extend Twig with PHP functions

1.0.0 2014-05-03 17:03 UTC

README

Build Status SensioLabsInsight

This Symfony2 bundle aims to provide a simple interface to extend Twig with PHP functions

Installation

Add requirements to composer.json:

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

Register the bundle

Register the bundle in the AppKernel.php file

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

Configuration

Add the configuration to config.yml

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

Twig

Use your functions, filters and test in Twig templates:

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