Twig 标签包含 vs 函数包含 [英] Twig tag include vs function include
问题描述
Twig's documentation for tag include looks very similar to that of function include.
标签包括:
{% include 'header.html' %}
功能包括:
{{ include('template.html') }}
有人能指出在什么情况下,一个比另一个更受欢迎吗?谢谢!
Can somebody point out in what circumstances, one is preferred over the other? Thanks!
推荐答案
{{ include() }}
是在 Symfony 2.2 中引入的:
{{ 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') }}
但正如 Fabien Potentier(Twig 创始人)所说
But as Fabien Potentier (twig founder) said
函数和标签确实是完全一样的
the function and the tag does indeed the exact same thing
你可以在这里找到关于它的介绍的讨论:https://github.com/twigphp/树枝/拉/926
You can find the discution about it's introduction here: https://github.com/twigphp/Twig/pull/926
这篇关于Twig 标签包含 vs 函数包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!