Ad

Shopify Liquid Syntax - What Is The Difference Between {%- Assign [some_var] = [some_val] -%} And {% Assign [some_var] = [some_val] %}

- 1 answer

When coding in Shopify's Liquid language I notice some variables being assigned using the following syntax:

{%- assign variable = value -%}

and other variables being assigned using the following syntax:

{% assign variable = value %}

Could someone explain the difference, if there is any?

Ad

Answer

When yo use {% assign variable = value %} you keep any white space if there is any.

But if you use {%- assign variable = value -%} the white space is stripped.

That's the main difference.

PS: This is true for any liquid operation{%- if -%}, {%- capture -%} etc.. even if you like to output something like so {{- -}}.

Ad
source: stackoverflow.com
Ad