如何在树枝中嵌入PHP [英] How to embed php in twig
本文介绍了如何在树枝中嵌入PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个do_shortcut,我需要将其嵌入到树枝模板中.我尝试通过处理PHP文件my-code.php中的代码进行尝试:
I have a do_shortcut and I need to embed it in a twig template. I tried by coping the code in a php file my-code.php:
<?php do_shortcut('[my-code]'); ?>
接下来,在树枝页面over.twig中:
Next, in the twig page over.twig:
{{ include ('options/my-code.php') }}
/* I also tried */
{% php %}
<?php do_shortcut('[my-code]'); ?>
{% endphp %}
但是不起作用.有什么建议吗?谢谢.
But doesn't work. Any suggestion? Thanks.
推荐答案
您不能这样做,您应该创建一个twig扩展名并将php函数转换为twig函数:
You can't do that, you should create a twig extension and transform the php function into a twig function: http://symfony.com/doc/current/cookbook/templating/twig_extension.html
这篇关于如何在树枝中嵌入PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文