Whitespace control in Shopify Liquid

jrbedard

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?

David Lazar

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related