Provides eval as a function in your twig templates.

v2.0.0 2022-06-16 14:19 UTC

This package is auto-updated.

Last update: 2023-09-11 23:02:08 UTC


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.


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 %}


Just run

$ vendor/bin/phpunit tests/EvalExtensionTest.php

No pesky phpunit.xml needed.


Please don't.

Known Issues

It's eval in your templates. What could possibly go wrong?!