jaem3l / twig-eval-extension
Provides eval as a function in your twig templates.
v2.0.0
2022-06-16 14:19 UTC
Requires
- twig/twig: ^2.7|^3.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-12 01:34:55 UTC
README
One of the goals of Twig is to limit the amount of logic in your templates.
Unfortunately you won't be able to do all sorts of stuff you can do with PHP.
To regain that power you can use TwigEvalExtension. Just write your php code
inside an eval()
template function and it gets passed to PHP's eval and you
will get the result.
Installation
You can install the extension by using composer require.
Example Usage
Using the eval function:
{{ eval('echo 1+1;') }}
Using the eval tag:
{% eval %} echo file_get_contents("/var/log/system.log"); {% endeval %}
Tests
Just run
$ vendor/bin/phpunit tests/EvalExtensionTest.php
No pesky phpunit.xml needed.
Contribution
Please don't.
Known Issues
It's eval in your templates. What could possibly go wrong?!