jrbedard
jrbedard

Reputation: 3730

Whitespace control in Shopify Liquid

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?

Upvotes: 3

Views: 2629

Answers (1)

David Lazar
David Lazar

Reputation: 11427

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.

Upvotes: 2

Related Questions