Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-17T15:37:32.827Z
Answers.Text: My god... what have I done? :)
Answers.UserDisplayName: andrew.welch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-18T10:20:03.173Z
Answers.Text: Only because you can, doesn't mean you should :)
Answers.UserDisplayName: KSPR
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-16T15:06:48.463Z
Answers.LastActivityDate: 2019-01-20T00:28:38.033Z
Answers.LastEditDate: 2019-01-20T00:28:38.033Z
Answers.UserDisplayName: KSPR
Body: <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>
  
Tags: <twigextension>
Title: PHP eval filter for Twig
ThreadText: # 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?](https://craftcms.stackexchange.com/questions/722/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 :)  
  
  ---
  
  