Whitespace
Outside of Liquid statements, all whitespace is preserved. This can result in whitespace that is unwieldy (for example, while formatting GraphQL queries).
To avoid this, use hyphens just inside of Liquid statement openings and closings, as in the following:
  • {{- eats_whitespace_on_the_left }}
  • {%- assign eats_whitespace_on_the_left = true %}
  • {{ eats_whitespace_on_the_right -}}
  • {% assign eats_whitespace_on_the_right = true -%}
  • {{- eats_whitespace_on_both_sides -}}
  • {%- assign eats_whitespace_on_both_sides -%}
Learn more from Shopify: see Whitespace control.

Example

1
{%- capture message -%}
2
This is a message.
3
{%- endcapture -%}
4
​
5
{% capture message -%}
6
This is a message.
7
{% endcapture -%}
8
​
9
{{- customer.name -}}
10
{{ customer.name -}}
11
{{- customer.name }}
Copied!
Last modified 7mo ago
Copy link
Edit on GitHub
Contents
Example