简体   繁体   中英

Include PHP in TWIG

I configured my Symfony's 2 project for accepting "twig" and "php" extension in " config.yml ' like that :

framework:
router:
    resource: "%kernel.root_dir%/config/routing_dev.yml"
    strict_requirements: true
profiler: { only_exceptions: false }    
templating:
    engines: ['twig', 'php'] 

But when i include a php file in twig, it doesn't interpreted PHP:

<h1>Reference ROBERT</h1>
<!--?php $name = "Jeremy" ?-->
<h1></h1>
" Hello "
<!--?php echo $name -->
"! "

But my php file has no comment. :(

There is another part at configured ?

Thanks.

You can't use php in Twig. twig has it's own syntax. Use it or use fully PHP templates!

If you need to call some php functions, write a twig extension.

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