<p>In Craft 3 it is actually possible.</p>

<pre><code>{{ craft.app.view.evaluateDynamicContent('phpinfo();') }}
</code></pre>

<p>See: <a href="https://craftcms.stackexchange.com/questions/722/can-we-use-php-in-our-templates-instead-of-twig">Can we use PHP in our templates instead of Twig?</a></p>

CC BY-SA 4.0
2019-01-17T15:37:32.827Z
My god... what have I done? :)
andrew.welch
CC BY-SA 4.0
2019-01-18T10:20:03.173Z
Only because you can, doesn't mean you should :)
KSPR
CC BY-SA 4.0
2019-01-16T15:06:48.463Z
2019-01-20T00:28:38.033Z
2019-01-20T00:28:38.033Z
KSPR
<p>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 <code>|php</code> filter for Twig that just does this? </p>

<pre><code>{% set text = "echo 'Hello World';" %) 
{{ text | php }} 
</code></pre>

<p>Filter function:</p>

<pre><code>function myPhpEvalFunction ($text = null) {
   return eval($text);
} 
</code></pre>

<twigextension>
PHP eval filter for Twig
# PHP eval filter for Twig

(Asked by: username_0 on 2019-01-16)

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

**Tags:** twigextension


---

## 1 answers

### Answer by username_1 on 2019-01-16. Score: 3 | Accepted answer

In Craft 3 it is actually possible.
{{ craft.app.view.evaluateDynamicContent('phpinfo();') }}

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

> **Comments:**
> **username_2**: My god... what have I done? :)  
> **username_1**: Only because you can, doesn't mean you should :)  

---

