Skip to content

Liquid

A safe template language for letting users customize pages without running their code on your server.

Stars
11.9k
Forks
1.5k
Licence
MIT
Language
Ruby
Last update
9 days ago
Type
Library

What it is

Liquid is a template engine, a tool that fills in placeholders in text or HTML with real data, such as a product name or price. It is designed so that the people writing templates can be non-programmers or untrusted users, because templates cannot run arbitrary code on the server. It is written in Ruby and installed as a gem.

  • Render a product list from data with a loop and filters, as in the README example
  • Let users edit page layouts in a theme editor while keeping the server secure
  • Use separate environments to register custom tags for email templates versus web pages
  • Turn on strict error modes to catch invalid template syntax while editing

Great for

  • Ruby developers who want to let customers or editors change the appearance of their app
  • Teams that render templates stored in a database
  • Projects that need one template format for both HTML pages and emails

Not ideal for

  • Developers who need a full general-purpose scripting language inside templates, since Liquid is intentionally limited
  • Projects not using Ruby, because the README only documents a Ruby gem
Step-by-step guide: how to use LiquidInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Ruby

    Add to Gemfile

    gem 'liquid'
  2. 2

    Run it

    • Add gem 'liquid' to your Gemfile and install dependencies
    • Parse a template with Liquid::Template.parse
    • Call render with a hash of variables to get the output
  3. 3

    Get the most out of it

    • Use Liquid::Environment.build to isolate custom tags and filters per context
    • Enable :strict or :warn error mode on new apps to catch invalid templates early
    • Pass strict_variables: true and strict_filters: true to find missing data during rendering
    • Use render! to raise on the first error instead of collecting them

Downloads

Strengths

  • Designed to be safe for user-edited templates, with no arbitrary code execution
  • Parsing can be done once and rendering reused with different data
  • Configurable error modes and strict variable and filter checks help debugging

Trade-offs

  • Default lax parsing accepts almost anything, so errors can go unnoticed unless strict modes are enabled
  • Resource limits only cover certain loops, and the README notes output-free loops need more care

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.