umpirsky/twig-php-function

Call (almost) any PHP function from your Twig templates.

0.2.0 2017-03-13 13:46 UTC

README

68747470733a2f2f6661726d322e737461746963666c69636b722e636f6d2f313730392f32353039383532363838345f616534643530343635665f6f5f642e706e67

symfony upgrade fixertwig gettext extractorwisdomcentipedepermissions handlerextraloadgravatarlocurrocountry listtransliterator

Twig PHP Function Build Status

Call (almost) any PHP function from your Twig templates.

Usage

After registering PhpFunctionExtension call PHP functions from your templates like this:

Hi, I am unique: {{ uniqid() }}.

And {{ floor(7.7) }} is floor of 7.7.

Extend

You can control allowed PHP functions by adding new ones like this:

$extension = new Umpirsky\Twig\Extension\PhpFunctionExtension();
$extension->allowFunction('hash_hmac');

or restrict what functions are allowed like this:

$extension = new Umpirsky\Twig\Extension\PhpFunctionExtension(['floor', 'ceil']);

If you think that some function should be allowed/not allowed, feel free to raise issue or submit a pull request.