Shopify Liquid

ยท 3 minute read

Unlock the full potential of a Shopify store with Liquid development. This tutorial series is liquid at a glance, and not a replacement for the official documentation.

NB: This note is taken from the Shopify Liquid Documentation

Basics ๐Ÿ”—

{{ }}

Double curly brace delimiters denote an output.

{% %}

Curly brace percentage delimiters denote logic and control flow.

{{ | }}

Filters are placed within an output tag and denoted by a pipe character.

Object Handles ๐Ÿ”—

{{ product.title | handle }}

Referencing Handles ๐Ÿ”—

{{ pages['about-us'].url }}

Operators ๐Ÿ”—

==equals
!=does not equal
>greater than
<less than
>=greater than or equal to
<=less than or equal to
orCondition A or Condition B
andCondition A and Condition B
containsChecks for strings in strings or arrays
{% if product.tags contains 'high' %}
	Check other cheap products
{% endif %}

Conditionals ๐Ÿ”—

{% if product.type == 'Love' %}
  This is a love potion!
{% elsif product.type == 'Health' %}
  This is a health potion!
{% endif %}

Including else

{% if product.available %}
  This product is available!
{% else %}
  This product is sold out!
{% endif %}

Using unless if the condition is true

{% if product.available %}
  This product is available!
{% else %}
  This product is sold out!
{% endif %}

Using case

{% case variable %}
  {% when first_value %}
    first_expression
  {% when second_value %}
    second_expression
  {% else %}
    third_expression
{% endcase %}

Tags ๐Ÿ”—

HTML Tags ๐Ÿ”—

{% form 'form_type' %}
  content
{% endform %}

Iteration Tags ๐Ÿ”—

{% for product in collection.products -%}
  {{ product.title }}
{%- endfor %}

Syntax Tags ๐Ÿ”—

{% comment %}
  content
{% endcomment %}
{% # content %}
{% raw %}
  expression
{% endraw %}

Theme Tags ๐Ÿ”—

{% javascript %}
  javascript_code
{% endjavascript %}
{% stylesheet %}
  css_styles
{% endstylesheet %}

Filters ๐Ÿ”—

Usage - {{ product.title | upcase }}

With parameters - {{ product.title | remove: 'Health' }}

Multiples - {{ product.title | upcase | remove: 'HEALTH' }}

Concat - array | concat: array

Map - array | map: string

Check documentation for more

Cart Filters ๐Ÿ”—

cart | item_count_for_variant: {variant_id}

Color Filters ๐Ÿ”—

string | brightness_difference: string

Customer filters ๐Ÿ”—

string | customer_login_link

{{ 'Create an account' | customer_register_link }}

Default filters ๐Ÿ”—

{{ product.selected_variant.url | default: product.url }}

Font filters ๐Ÿ”—

{{ settings.type_header_font | font_face }}

Other types of filters ๐Ÿ”—

  • Collection
  • Format (date, unit)
  • HTML
  • Hosted file
  • Localization
  • Math
  • Media
  • Metafield
  • Money
  • Payment
  • String
  • Tag

Objects ๐Ÿ”—

Usage ๐Ÿ”—

Objects, along with their properties, are wrapped in curly brace delimiters {{ }}

{{ product.title }}

{% assign article = articles['potion-notions/new-potions-for-spring'] %}
{{ article.title | link_to: article.url }}

Learn More - Shopify Documentation