Whitespace control
In Liquid, you can include a hyphen in your tag syntax {{-
, -}}
, {%-
, and -%}
to strip whitespace from the left or right side of a rendered tag.
Normally, even if it doesn’t print text, any line of Liquid in your template will still print a blank line in your rendered HTML:
Input
Notice the blank line before “tomato” in the rendered template:
Output
By including a hyphen in your assign
closing delimiter, you can strip the whitespace following it from the rendered template:
Input
Output
If you don’t want any of your tags to print whitespace, as a general rule you can add hyphens to both sides of all your tags ({%-
and -%}
):
Input
Output without whitespace control
Input
Output with whitespace control
Last updated