Twig tag include vs function include

2019-06-14 23:22发布

Twig's documentation for tag include looks very similar to that of function include.

Tag include:

{% include 'header.html' %}

Function include:

{{ include('template.html') }}

Can somebody point out in what circumstances, one is preferred over the other? Thanks!

标签: php twig
1条回答
祖国的老花朵
2楼-- · 2019-06-14 23:33

{{ include() }} Was introduce in Symfony 2.2:

Using a function allows you to do whatever you want with the output (which is not possible with a tag), like a simple:

{{ set content = include('some_template') }}

But as Fabien Potentier (twig founder) said

the function and the tag does indeed the exact same thing

You can find the discution about it's introduction here: https://github.com/twigphp/Twig/pull/926

查看更多
登录 后发表回答