umpirsky / twig-php-function
Call (almost) any PHP function from your Twig templates.
Installs: 3 705 763
Dependents: 3
Suggesters: 0
Security: 0
Stars: 60
Watchers: 6
Forks: 20
Open Issues: 1
Requires
- php: ^8.0
- twig/twig: ^3.0
Requires (Dev)
- phpspec/phpspec: ^7.5
- phpunit/phpunit: ^9.6
This package is not auto-updated.
Last update: 2024-07-23 16:03:46 UTC
README
symfony upgrade fixer • twig gettext extractor • wisdom • centipede • permissions handler • extraload • gravatar • locurro • country list • transliterator
Twig PHP Function ![Build Status](https://camo.githubusercontent.com/2554127113460467744e76c47b078f9406066489b641ab645586e479de607e5a/68747470733a2f2f7472617669732d63692e6f72672f756d706972736b792f747769672d7068702d66756e6374696f6e2e7376673f6272616e63683d6d6173746572)
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.