I expected the following:
{% spaceless %}
blablabla
blablabla
blablabla
blablabla
blablabla
{% endspaceless %}
to return the following string:
blablabla blablabla blablabla blablabla blablabla
but in the page source, I see this:
blablabla
blablabla
blablabla
blablabla
blablabla
How to do this without any HTML <tags>
?
As of Twig 2.7, use the spaceless filter instead. This tag is not meant to "optimize" the size of the generated HTML content but merely to avoid extra whitespace between HTML tags to avoid browser rendering quirks under some circumstances.
Whitespace can be removed by using the modifier - in the description of Twig tags and variables.
As explained in the documentation, "Use the spaceless tag to remove whitespace between HTML tags, NOT whitespace within HTML tags or whitespace in plain text:"
{% spaceless %}
<div>blablabla</div>
<div>blablabla</div>
<div>blablabla</div>
<div>blablabla</div>
<div>blablabla</div>
{% endspaceless %}
Will output:
<div>blablabla</div><div>blablabla</div><div>blablabla</div><div>blablabla</div><div>blablabla</div>
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