简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM