Just updated from Twig 2.*
to Twig 3.*
Most of my templates are wrapped in the {% autoescape %} ... {% endautoescape %}
block
And some templates have {% spaceless %} ... {% endspaceless %}
block inside.
In final it looks like this:
{% autoescape %}
...
{% spaceless %}
...
{% endspaceless %}
...
{% endautoescape %}
And now (after the update to 3.*
) I get SyntaxException
from Twig.
How should these block be rewritten/supported?
Why such construction is no longer supported by the Twig?
Fatal error: Uncaught Twig\Error\SyntaxError: Unexpected "spaceless" tag (expecting closing tag for the "autoescape" tag defined near line 2). in
You need to use the apply
tag now, e.g.
{% apply spaceless %}
...
{% endapply %}
reference
The reason is for this construction is to have a consistent codebase as you now can "apply" filter(s) to chunk of texts, e.g.
{% apply upper %}
This {{ text }} becomes uppercase
{% endapply %}
whereas you needed to concat it in the past and add parentheses
{{ ('This '~text~' becomes uppercase')|upper }}
TLDR To be consistent they've decided to remove the tag spaceless and to introduce the filter spaceless
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