explaingit

shopify/liquid

11,786RubyAudience · developerComplexity · 2/5Setup · easy

TLDR

Liquid is a safe, sandboxed template engine from Shopify that lets users customize web app layouts with variables, loops, and filters without being able to run arbitrary server-side code.

Mindmap

mindmap
  root((liquid))
    What It Does
      Safe template rendering
      User-editable layouts
      Two-step parse and render
    Syntax
      Variable output
      Loops and conditionals
      Filters
    Features
      Multiple Environments
      Strict error mode
      Lenient default mode
    Use Cases
      Shopify themes
      Email templates
      Multi-tenant apps
    Audience
      Ruby developers
      SaaS builders
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a theme system that lets non-developers customize web page layouts without risking server security.

USE CASE 2

Create an email templating system where end users personalize content using their own variables and filters.

USE CASE 3

Render HTML safely from database-stored templates in a multi-tenant SaaS app.

USE CASE 4

Add separate template environments for different contexts like storefronts versus transactional emails.

Tech stack

Ruby

Getting it running

Difficulty · easy Time to first run · 30min

In plain English

Liquid is an open-source template engine created by Shopify, written in Ruby. It was built to let users customize the appearance of web applications by editing templates, without allowing those users to run arbitrary code on the server. This makes it suitable for situations where template files come from end users or are stored in a database, rather than being written by trusted developers. The key design goal is safety. Liquid templates can output variables, loop over lists, apply conditional logic, and use filters to format values, but they cannot call arbitrary Ruby methods or execute server-side code. The engine is also stateless: parsing a template and rendering it are two separate steps, so a template can be compiled once and then rendered many times with different data, which makes repeated use efficient. The syntax uses double curly braces for output (for example, a product name or price) and curly brace percent signs for logic (such as loops and conditionals). This style will be familiar to anyone who has used Shopify themes or other template languages like Twig or Jinja. A feature called Environments lets developers register different sets of custom tags and filters for different contexts, for example separate configurations for storefront pages versus email templates. This keeps customizations isolated and prevents them from interfering with each other. The parser also supports different error modes, ranging from fully lenient (the default, which accepts almost anything) to strict (which raises errors for invalid syntax), which is useful when building template editors where users should see clear feedback. Liquid is the engine behind Shopify themes and is used in several other projects that need safe, user-editable templates.

Copy-paste prompts

Prompt 1
Using Shopify's Liquid gem in Ruby, write a template that loops over a list of products, shows their name and price, and applies a discount filter.
Prompt 2
How do I register a custom Liquid filter in Ruby that formats a number as a currency string with two decimal places?
Prompt 3
Set up two separate Liquid Environments in Ruby, one for storefront templates and one for email templates, each with different allowed tags.
Prompt 4
I have a Liquid template stored in a database. Show me how to parse it once and render it multiple times with different data hashes in Ruby.
Prompt 5
Configure Liquid in strict error mode and write a Ruby test that verifies invalid template syntax raises the correct exception.
Open on GitHub → Explain another repo

← shopify on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.