Trim whitespace in scripting tags
Using tag modifiers
Adding a dash -
to opening or closing scripting tags will trim leading or trailing whitespace.
-
start: return: output@text: This text {{-" has no leading or trailing whitespace "-}} in it.
-
__return: output: This text has no leading or trailing whitespace in it.
Using |spaceless filter
The |spaceless
filter removes whitespace between HTML tags.
-
start: return: output@text: {{ "<div> <p>This has extra space</p> <p>between tags</p> </div>"|spaceless }}
-
__return: output: <div><p>This has extra space</p><p>between tags</p></div>
Using apply spaceless
For larger blocks of HTML, you can use the apply spaceless approach.
-
start: return: output@text: {% apply spaceless %} <div> <span>This will all be on a single line.</span> </div> {% endapply %}
-
__return: output: <div><span>This will all be on a single line.</span></div>