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 output text, any line of Liquid in your template will still output an empty line in your rendered HTML:

Order history:

{% if customer %}
Welcome back, {{ customer.first_name }}
{% endif %}

Notice that there are two empty lines in the rendered template:

Order history:


Welcome back, Martina

By including hyphens in your Liquid tag, ({%- and -%}), you can strip the generated whitespace from the rendered template:

Order history:

{%- if customer -%}
Welcome back, {{ customer.first_name }}
{%- endif -%}
Order history:

Welcome back, Martina

Did this page help you?