Ad

Whitespace Control In Shopify Liquid

- 1 answer

Shopify recently added whitespace control to the Liquid templating language: https://help.shopify.com/themes/liquid/basics/whitespace

You essentially add an hyphen in your tag syntax {{- -}}, {%- -%} to strip whitespace (html empty line) outputted by a tag. For example:

{%- assign variable = "hello" -%}
{{ variable }}

Renders:

hello

Instead of:

 
hello

Is there a way to turns this on for all assign tags? and/or all specific control flow or iteration tags?

Ad

Answer

Indeed. You turn it on when you type your Liquid. Let your fingers do that talking!

If you load up your theme in a text editor, you can use the common Find All command to find all instances of assign. Use that to replace the surrounding {% %} with {%- -%}. Pretty much all there is to it. Repeat for any keywords you like.

Ad
source: stackoverflow.com
Ad