简体   繁体   中英

Rendering Twig template in PHP template

I am rendering a PHP template with Symfony 2, the template code I have:

phptemplate.html.php :

...
<?php echo $view->render('MyBundle:Def:info.html.twig', array('m' => $m)) ?>
...

MyBundle:Def:info.html.twig :

abc
{{ url('form_individual') }}
{{ m.test }}
abc

Output display result :

abc
{{ url('form_individual') }}
{{ m.test }}
abc

Variables are not rendered but instead are displayed as text, why?

PhpEngine , which in fact you used, doesn't support twig templates. So, your twig template is (probably) parsed as a plain text.

PhpEngine supports method Source code and here base doc for supports where is: Returns true if this class is able to render the given template. .

Why you didn't rewrite your MyBundle:Def:info.html.twig template to php? Or parent one to twig ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM