Cheatsheet for Liquid on Jekyll
Posted: 2024-01-24, Updated:2024-01-25
Tags: Liquid, Jekyll
This is a compilation of information from Shopify’s Liquid documentation and Jekyll’s Liquid documentation.
Liquid is a templating language. There are three main components:
- Objects - Content/variables to be added to a page. Enclosed in
{{
and}}
. - Filters - Change the output of an object/variable, placed inside the object’s curly-braces (or inside of a variable assignment) after a vertical pipe character
|
. - Tags - Implement logic, control flow, and variable assignments. Enclosed in
{%
and%}
.
Jekyll provides a bunch of variables that can be accessed through Liquid.
Objects, Tags, and Filters
Objects
Objects contain content to be displayed. Objects and variables are are displayed when enclosed in double curly braces:
Boolean
Booleans are either true
or false
. (No quotes; if quotes are used the variable will be a string instead of a boolean.)
{% assign foo = true %}
{% assign bar = false %}
Number
Numbers can be floats or integers.
{% assign my_int = 25 %}
{% assign my_float = -39.756 %}
String
Strings are sequences of characters wrapped in single or double quotes:
{% assign my_string = "Hello World!" %}
Liquid does not convert escape sequences into special characters.