CSS: When to use Flexbox, when to use Grid
Learn when to use CSS Flexbox vs. Grid, with examples for each. Understand their technical differences and how to combine them for modern, responsive web design.
Variables enclosed in double curly braces, e.g.,
{{ product.title }}
.
{% if condition %}...{% endif %}
.|
), e.g.,{{ product.price | money }}
.if
#Used for conditional logic.
{% if product.available %}
In stock
{% else %}
Out of stock
{% endif %}
for
#Iterates over a collection.
{% for item in collection %}
{{ item.title }}
{% endfor %}
assign
#Assigns a value to a variable.
{% assign discount = 0.1 %}
capture
#Captures content into a variable.
{% capture message %}
Welcome to our store!
{% endcapture %}
include
#Includes a template file.
{% include 'header' %}
default
#Provides a default value if the variable is empty.
{{ product.description | default: "No description available." }}
date
#Formats a date.
{{ "now" | date: "%Y-%m-%d" }}
money
#Formats a number as currency.
{{ product.price | money }}
split
#Splits a string into an array.
{% assign tags = product.tags | split: ',' %}
join
#Joins an array into a string.
{{ tags | join: ', ' }}
case
#Handles multiple conditions.
{% case product.type %}
{% when 'shirt' %}
This is a shirt.
{% when 'pants' %}
This is a pair of pants.
{% else %}
Product type not recognized.
{% endcase %}
cycle
#Cycles through values in a loop.
{% for item in collection %}
<div class="{% cycle 'odd', 'even' %}">{{ item.title }}</div>
{% endfor %}
raw
#Prevents Liquid code from being processed. Simply use raw
and endraw
, each written inside the {% %}
tag markers. Everything between the tags will not be interpreted by Liquid.
Sources and recommended, further resources on the topic:
Liquid cheat sheet by Jonas Jared Jacek is licensed under CC BY-SA 4.0.
This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/liquid-cheat-sheet">Liquid cheat sheet</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>
For more information see the Ditig legal page.
“Premature optimization is the root of all evil.”