Skip to content
Advertisement

Twig tag include vs function include

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

Tag include:

JavaScript

Function include:

JavaScript

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

Advertisement

Answer

{{ 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:

JavaScript

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

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement