macwinnie / twig-php-function
Call (almost) any PHP function from your Twig templates.
Installs: 26
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 18
pkg:composer/macwinnie/twig-php-function
Requires
- php: ^7.4 || ^8.0
- twig/twig: ^1.28 || ^2.0 || ^3.0
Requires (Dev)
- phpspec/phpspec: ^4.3.4 || ^5.0 || ^6.0
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2025-11-18 03:42:43 UTC
README
symfony upgrade fixer • twig gettext extractor • wisdom • centipede • permissions handler • extraload • gravatar • locurro • country list • transliterator
Twig PHP Function 
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.