If I am confident in the users of our webpage that they will never be messing with the Twig templates, then what risk is there to creating a |php filter for Twig that just does this?

{% set text = "echo 'Hello World';" %) 
{{ text | php }} 

Filter function:

function myPhpEvalFunction ($text = null) {
   return eval($text);

1 Answer 1


In Craft 3 it is actually possible.

{{ craft.app.view.evaluateDynamicContent('phpinfo();') }}

See: Can we use PHP in our templates instead of Twig?

  • 1
    My god... what have I done? :) Commented Jan 17, 2019 at 15:37
  • Only because you can, doesn't mean you should :)
    – KSPR
    Commented Jan 18, 2019 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.