ZHENESJAKOTHVIRUFRAR

Liquid

Liquid is an open-source, Ruby-based template language created by Shopify that lets developers inject dynamic logic and store data into otherwise static HTML, so a single theme file can render different content for every visitor, product, and page.


The Real-Life Analogy: A Mad Libs With Rules

Imagine a Mad Libs book. The story skeleton is already printed — "Welcome to ___, your total is ___." Your job is to fill in the blanks with the right words. Liquid works the same way: your .liquid theme files are the story skeleton (HTML, CSS, structure), and Liquid tags are the blanks that get filled at render time with real data — a customer's name, a product's price, a collection's title.

The difference is that Liquid blanks come with grammar. You can't just drop any word in. You can write *"if the customer is logged in, show their name; otherwise, show 'Sign in'"* — and Liquid will follow that instruction every time the page loads, for every one of your visitors, without you writing a separate page for each one.

That's the whole idea: static structure + dynamic instructions = a page that's different for everyone but maintained in one place.


The Core Formula

Every piece of Liquid output follows the same three-part logic:

{{ output }} + {% logic %} + [filters] = rendered content

- {{ ... }} — Output tags. These print a value to the page. {{ product.title }} outputs the title of the current product.

- {% ... %} — Logic tags. These control flow and don't print anything themselves. {% if product.available %}, {% for item in cart.items %}, {% assign total = 0 %}.

- | — Filters. These transform output. {{ product.price | money }} converts a raw number like 1999 into $19.99. Filters chain: {{ product.title | upcase | truncate: 20 }}.

A real snippet from a Shopify theme might look like:

{% if cart.item_count > 0 %}
  <p>You have {{ cart.item_count }} items — total: {{ cart.total_price | money }}</p>
{% else %}
  <p>Your cart is empty.</p>
{% endif %}

Read it in plain English: *If the cart has more than zero items, show the count and formatted total; otherwise, tell them it's empty.* That's the entire mental model.


Liquid vs. Related Terms

TermWhat it isHow it differs from LiquidWhere you'd use it
**Liquid**Template language (Shopify)The rendering layer itself — logic + outputTheme files, emails, checkout extensions
**HTML**Markup languageStatic structure only; no logic or dataThe skeleton Liquid writes into
**JavaScript**Client-side programming languageRuns in the browser *after* the page loads; Liquid runs on the server *before*Interactivity, cart drawers, dynamic widgets
**JSON**Data formatPure data, no logic; Liquid often outputs JSONProduct data, API responses, metafields
**Twig / Jinja**Template languages (PHP / Python)Same concept, different syntax and ecosystemsWordPress, Django, Flask
**Liquid Objects**Data structures (product, cart, shop)The *data* Liquid operates on, not the languageAccessed inside `{{ }}` and `{% %}`

The key distinction: Liquid is server-side. By the time the page reaches the browser, all Liquid has already been resolved into plain HTML. JavaScript is what runs afterward.


Use Cases

Liquid powers far more than product pages. Common applications include:

1. Theme rendering — Every Shopify storefront (Dawn, Impulse, custom themes) is built on Liquid. A single product.liquid template renders thousands of product pages.

2. Dynamic pricing and promotions — Show a "20% off" badge only when product.compare_at_price > product.price.

3. Personalized content — Display a loyalty message to logged-in customers using {% if customer %}.

4. Email templates — Shopify's transactional emails (order confirmation, shipping updates) use Liquid to pull in order data.

5. Checkout UI extensions — Custom checkout fields and messaging use Liquid-flavored logic.

6. Section and block architecture — Modern themes use {% schema %} to let merchants drag-and-drop sections without touching code.

7. Metafield rendering — Display custom data (ingredients, specs, size charts) stored on products.

A store with 5,000 SKUs and 12 collections might have just 15–30 Liquid template files doing all the rendering work — that leverage is the entire point.


Common Misconceptions

"Liquid is a programming language."

It's a *templating* language. It's intentionally limited — no loops-within-loops beyond a certain depth, no user-defined functions, no complex math. This is a feature, not a bug: it keeps themes safe for merchants to customize without breaking the store.

"Liquid runs in the browser."

No. Liquid is processed on Shopify's servers. View source on any Shopify page and you'll see pure HTML — no {{ }} anywhere. If you need browser-side logic, that's JavaScript.

"I need to learn Ruby to use Liquid."

No. Liquid was *built* in Ruby, but you write Liquid, not Ruby. The syntax is closer to a simplified Twig than to any full programming language.

"Liquid is only for Shopify."

It's open-source and used by Jekyll, Salesforce, Zendesk, and others. But its richest implementation — with the most objects, filters, and tags — is Shopify's.

"More Liquid = better theme."

The opposite is often true. Heavy Liquid logic slows server render time. Best practice is to keep templates lean and push complexity into metafields, sections, or app blocks.

"Liquid can do anything."

It can't query external APIs, can't write to a database, and can't run background jobs. It reads data Shopify hands it and renders it. That's the boundary.


Related Terms

- Shopify Theme — The collection of Liquid, JSON, CSS, and asset files that define a store's appearance.

- Section — A reusable, merchant-configurable Liquid component (e.g., a hero banner) with its own {% schema %}.

- Snippet — A smaller reusable Liquid file included via {% render 'snippet-name' %}.

- Object — A data structure Liquid can access (product, collection, cart, customer, shop).

- Filter — A modifier applied with | to transform output (money, date, json, escape).

- Tag — A {% %} statement controlling logic (if, for, assign, render, schema).

- Metafield — Custom data attached to Shopify resources, rendered via Liquid.

- Dawn — Shopify's default reference theme, a modern Liquid codebase worth studying.

- Hydrogen / Storefront API — Shopify's headless alternative, where Liquid is replaced by React and GraphQL.