1

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);
} 
3

In Craft 3 it is actually possible.

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

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

|improve this answer|||||
  • 1
    My god... what have I done? :) – andrew.welch Jan 17 '19 at 15:37
  • Only because you can, doesn't mean you should :) – KSPR Jan 18 '19 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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