CocoShop theme development
  • 🚀Getting Started
    • Overview
    • Getting started
  • ⛓️Architecture
    • Overview
    • Layouts
    • Templates
      • index
      • collections
      • collection
      • product
      • 404
      • search
      • page
    • Section
      • Section schema
    • Config
    • Input settings
  • 💧Liquid
    • Basics
      • Operators
      • Truthy and Falsy
      • Whitespace Control
    • Tags
      • Control flow
      • Variable
      • Theme
    • Filters
    • Objects
      • site
      • collection
      • wallet
      • chain
      • product
      • attribute
      • connected_wallet
      • linklists
      • linklist
      • link
    • Functions
      • connectWallet
      • changeChain
      • disconnect
      • transfer
      • buy
  • 💫Others
    • Roadmap
Powered by GitBook
On this page
  • 1. Arithmetic Operators
  • 1.1. Addition (+)
  • 1.2. Subtraction (-)
  • 1.3. Multiplication (*)
  • 1.4. Division (/)
  • 1.5. Modulo (%)
  • 2. Comparison Operators
  • 2.1. Equal (==)
  • 2.2. Not Equal (!=)
  • 2.3. Greater Than (>)
  • 2.4. Less Than (<)
  • 2.5. Greater Than or Equal To (>=)
  • 2.6. Less Than or Equal To (<=)
  • 3. Logical Operators
  • 3.1. AND (and)
  • 3.2. OR (or)
  • Summary
  1. Liquid
  2. Basics

Operators

Operators in Liquid are essential for comparing and combining variables in theme templates. They enable theme developers to create logic and conditional statements. This document provides an overview of the available operators in Liquid and their usage.

1. Arithmetic Operators

Arithmetic operators perform mathematical operations between two values or variables.

1.1. Addition (+)

Adds two values.

Example:

{{ product.price + additional_price }}

1.2. Subtraction (-)

Subtracts one value from another.

Example:

{{ product.price - discount }}

1.3. Multiplication (*)

Multiplies two values.

Example:

{{ product.price * quantity }}

1.4. Division (/)

Divides one value by another.

Example:

{{ product.price / installments }}

1.5. Modulo (%)

Returns the remainder of a division operation.

Example:

{{ product.reviews_count % 10 }}

2. Comparison Operators

Comparison operators are used to compare two values or variables.

2.1. Equal (==)

Returns true if the values on both sides of the operator are equal.

Example:

{% if product.price == 0 %}
  Free
{% endif %}

2.2. Not Equal (!=)

Returns true if the values on both sides of the operator are not equal.

Example:

{% if product.price != 0 %}
  Paid
{% endif %}

2.3. Greater Than (>)

Returns true if the value on the left is greater than the value on the right.

Example:

{% if product.inventory_quantity > 0 %}
  In stock
{% endif %}

2.4. Less Than (<)

Returns true if the value on the left is less than the value on the right.

Example:

{% if product.inventory_quantity < 10 %}
  Low stock
{% endif %}

2.5. Greater Than or Equal To (>=)

Returns true if the value on the left is greater than or equal to the value on the right.

Example:

{% if product.rating >= 4 %}
  Highly rated
{% endif %}

2.6. Less Than or Equal To (<=)

Returns true if the value on the left is less than or equal to the value on the right.

Example:

{% if product.rating <= 2 %}
  Poorly rated
{% endif %}

3. Logical Operators

Logical operators are used to combine multiple conditions.

3.1. AND (and)

Returns true if both conditions are true.

Example:

{% if product.available and product.featured %}
  Featured and available
{% endif %}

3.2. OR (or)

Returns true if at least one of the conditions is true.

Example:

{% if product.on_sale or product.clearance %}
  On sale or clearance
{% endif %}

Summary

Understanding and using operators in Liquid is crucial for creating dynamic, responsive, and flexible theme templates. By using arithmetic, comparison, and logical operators, you can build complex logic and conditional statements to tailor your theme's appearance and behavior to specific scenarios.

PreviousBasicsNextTruthy and Falsy

Last updated 1 year ago

💧