umpirsky/twig-php-function

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

Maintainers

Package info

github.com/umpirsky/twig-php-function

pkg:composer/umpirsky/twig-php-function

Statistics

Installs: 4 373 402

Dependents: 3

Suggesters: 0

Stars: 64

Open Issues: 1

0.2.1 2024-03-19 14:31 UTC

This package is not auto-updated.

Last update: 2026-03-03 23:24:27 UTC


README

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.