Skip to main content
Glama
01-basics.md3.49 kB
# Liquid Basics - Complete Guide ## Overview Liquid is a template language that enables developers to interact with data through tags, filters, and objects. This guide covers fundamental concepts necessary for effective Liquid implementation. ## Object Handles Objects representing store resources (products, collections, articles, blogs) use handles for identification and URL construction. ### Handle Generation Rules Handles follow standardized formatting: - Always lowercase - Whitespace and special characters convert to hyphens - Multiple consecutive special characters become a single hyphen - Leading whitespace or special characters are removed - Duplicate titles auto-increment (e.g., `potion` and `potion-1`) **Important:** Changing a resource title after creation does not update its handle. Individual links within `linklists` have handles based on titles but cannot be modified directly. ### Referencing Handles Objects with handles expose a `handle` property. Access methods include: **Square Bracket Notation:** `pages['about-us'].url` - Accepts quoted handles, variables, or object references **Dot Notation:** `settings.predictive_search_enabled` - Accepts unquoted handles ## Logical and Comparison Operators | Operator | Function | |----------|----------| | `==` | Equals | | `!=` | Does not equal | | `>` | Greater than | | `<` | Less than | | `>=` | Greater than or equal to | | `<=` | Less than or equal to | | `or` | Condition A or Condition B | | `and` | Condition A and Condition B | | `contains` | String/array presence check | ### The `contains` Operator The `contains` operator checks for string presence within strings or arrays. It cannot validate object existence in object arrays. ### Order of Operations Operators evaluate right-to-left without changeable precedence. "Parentheses are invalid characters within Liquid tags and will prevent rendering." ## Data Types Liquid supports six data types: ### String Any character series wrapped in single or double quotes. Use the `blank` object to check for empty strings. ### Number Numeric values including floats and integers. ### Boolean Binary values: `true` or `false`. ### Nil Undefined values that print nothing and evaluate as `false`. A string containing "nil" differs from the `nil` type. ### Array Variable lists accessible through loops or index notation starting at zero. Arrays cannot be initialized in Liquid alone but can be created using the split filter. ### Empty An `empty` object returns when accessing undefined objects (deleted pages, products, or valueless settings). Compare objects with `empty` before accessing attributes. ## Truthy and Falsy Values Understanding truthiness is critical for conditional logic: **Falsy Values:** - `false` - `nil` **Truthy Values:** - `true` - Empty strings - `0` (zero) - Integers and floats - Arrays (including empty arrays) - Pages and objects **Key Consideration:** Empty strings are truthy—use `blank` for validation. `EmptyDrop` objects are also truthy—compare with `empty` for proper checking. ## Whitespace Control Liquid tags generate output lines regardless of text content. Include hyphens in tag syntax to strip surrounding whitespace. **Syntax Examples:** - `{%- tag -%}` removes whitespace on both sides - `{%- tag %}` removes left-side whitespace only - `{% tag -%}` removes right-side whitespace only This technique prevents unwanted blank lines in rendered output while maintaining code readability.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/florinel-chis/shopify-liquid-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server