Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shopify: Why does Liquid sometimes use {%- instead of {%?

Tags:

shopify

liquid

I've been looking through the code of the default theme, and I've noticed that sometimes they use the {% tag to indicate Liquid code (as per the documentation), but other times they use {%-.

For example:

  {% case section.settings.image_size %}
    {% when 'small' %}
      {%- assign product_image_width = 'medium-up--one-third' -%}
      {%- assign product_description_width = 'medium-up--two-thirds' -%}

I cannot find a single example of {%- in the Liquid documentation, either on the Shopify site, or on GitHub, but I've seen other people use it on the Shopify forums, too.

What does the addition of a - signify?

like image 569
Chuck Le Butt Avatar asked Dec 19 '16 17:12

Chuck Le Butt


People also ask

Does Shopify still use Liquid?

Liquid was developed by Shopify co-founder and CEO Tobias Lütke and is now available as an open source project on GitHub. Today, it's used in many different software projects, from content management systems to static site generators—and of course, Shopify.

How does Shopify Liquid differ from HTML?

A liquid file is a mix of standard HTML code and Liquid constructs. It's an easy to read syntax, and is easy to distinguish from HTML when working with a Liquid file. This is made even easier thanks to the use of two sets of delimiters.

What language is Shopify Liquid?

Liquid is an open-source template language created by Shopify and written in Ruby. It is the backbone of Shopify themes and is used to load dynamic content on storefronts.

How does Shopify Liquid work?

The Liquid code is essentially a placeholder. It's used to retrieve specific referenced data from your Shopify store—like your store name, product details, images, etc. —when the code is compiled and sent to the browser. Then, the browser grabs assets like your Javascript and CSS files to display your customized theme.


1 Answers

The hyphens are a new syntax option that you can use to suppress blank lines that would otherwise show up in the source. You can learn more about this here: https://shopify.github.io/liquid/basics/whitespace/

like image 198
Josh Brown Avatar answered Sep 22 '22 07:09

Josh Brown