I wanted to do something like this:
{{ include("tpl.html")|f }}
But that doesn't seem to work, it just printed tpl.html
without any filtering, then I tried:
{% filter f %}
{% include "tpl.html" %}
{% endfilter %}
And it worked. I just wonder, why can't I use shorter one? Do I misunderstand something? Thanks in advance.
Sorry for being that long to come back :-)
The fact is that the include
function writes on the template.
If you do :
{% set s = include('FuzHomeBundle:Default:test.html.twig') %}
Which is not supposed to display something, you'll get the content of the file output anyway, and the s
variable will be set to null
.
If you do instead :
{% filter upper %}
{% include 'FuzHomeBundle:Default:test.html.twig' %}
{% endfilter %}
or
{% filter upper %}
{{ include('FuzHomeBundle:Default:test.html.twig' }}
{% endfilter %}
The filter
tag will compile some code that control output buffer.
To apply a filter on a section of code, you have to wrap it with the filter tag:
{% filter f %}
...
{% endfilter %}
What you were trying originally is to filter a variable which in twig is defined by the double parenthesis:
{{ variable name|filter }}
to read more check out the twig documentation on filters here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With