LiquidTags & Snippets

Tags & Snippets

Tags are the {% … %} parts of a template: conditions, loops, variables, and Joomni's tags for CSS, JavaScript and snippets. This page lists every one, and the two a section cannot use.

All tags

TagWhat it does
{{ … }}Output a value, optionally through filters.
{% if %} {% elsif %} {% else %} {% endif %}Branch. Operators: == != > < >= <= and or contains.
{% unless %}The opposite of if.
{% case %} {% when %}Switch on a value.
{% for item in list %}Loop. Supports limit:, offset:, reversed, ranges (1..5), {% else %} for empty lists, {% break %} and {% continue %}.
{% assign x = … %}Set a variable.
{% capture x %}…{% endcapture %}Set a variable to rendered text.
{% increment %} {% decrement %}Counters.
{% cycle %}Alternate between values inside a loop.
{% tablerow %}Rows of an HTML table.
{% comment %} {% # inline %}Not rendered.
{% raw %}Output Liquid syntax literally.
{% liquid %}Several tags in one block, one per line, without delimiters.
{% echo %}Output, inside {% liquid %}.
{% style %}…{% endstyle %}A <style> whose body can use Liquid: {% style %}.x { color: {{ section.settings.color }} }{% endstyle %}
{% stylesheet %}…{% endstylesheet %}Static CSS. Rendered inline, as text, with no Liquid inside.
{% javascript %}…{% endjavascript %}Static JavaScript. Rendered as a <script> where you wrote it, with no Liquid inside.
{% render 'name', key: value %}Render one of the theme’s snippets. Also with value as alias, and for list as item.
{% schema %}…{% endschema %}The settings declaration. Stripped before rendering.

The control-flow tags are covered with live examples in Liquid basics. The rest of this page is about the tags specific to themes.

CSS: style and stylesheet

{% style %} renders its body inside a <style> and lets Liquid run inside it, which is how CSS reads a setting. {% stylesheet %} is for CSS that never changes: Liquid inside it is not run. A plain <style> tag works too.

style and stylesheetliquid
{% schema %}
{
"name": "Callout",
"settings": [
{ "id": "text", "type": "text", "label": "Text", "default": "Free delivery this week" },
{ "id": "bg", "type": "color", "label": "Background", "default": "@color.accent" },
{ "id": "radius", "type": "range", "label": "Radius", "default": 12, "min": 0, "max": 32, "step": 2 }
]
}
{% endschema %}
{% style %}
.co-{{ section.id }} {
background: {{ section.settings.bg }};
color: var(--color-on-accent);
border-radius: {{ section.settings.radius }}px;
}
{% endstyle %}
{% stylesheet %}
.co { margin: 24px; padding: 20px 24px; font: 600 18px/1.4 var(--font-heading); }
{% endstylesheet %}
<div class="co co-{{ section.id }}">{{ section.settings.text }}</div>

Scope every selector

CSS in a section applies to the whole page. Put section.id in your class names (.co-{{ section.id }}) so two copies of the section, or another theme's section, never restyle each other.

JavaScript

A section can carry its own script in a <script> tag or a {% javascript %} block. Liquid runs inside a <script> tag, so it can name the section's own elements, as below. Liquid does not run inside {% javascript %}, which is for code that never changes: put the values it needs in data- attributes on your markup and read them from there.

A section with a scriptliquid
{%- assign root = 'count-' | append: section.id -%}
<div id="{{ root }}" data-target="120"
style="padding: 32px; font: 600 40px var(--font-heading); text-align: center;">0</div>
<script>
// Liquid runs inside a <script> tag, so the id is this section's own.
// The script runs once the section is on the page: DOMContentLoaded has already fired.
(function () {
var el = document.getElementById('{{ root }}');
if (!el || el.dataset.bound) return; // never bind twice
el.dataset.bound = '1';
var target = Number(el.dataset.target), n = 0;
var timer = setInterval(function () {
n = Math.min(target, n + 7);
el.textContent = n === target ? target + '+' : n;
if (n === target) clearInterval(timer);
}, 40);
})();
</script>
RuleWhy
Run your code straight awayThe storefront runs the script once the section is on the page. DOMContentLoaded and load have already fired.
Find your root by an id built from section.idThere can be two copies of your section on a page. A global querySelector finds the wrong one.
Do not bind twiceScripts run again when a shopper comes back to the page. Mark the element once bound, as above.
Page sections, header and footer onlyScripts do not run in the cart drawer, quick add or checkout templates.
Keep it short and readableEvery section with a script is read by a reviewer before a theme is published.

Scripts may not read cookies, use eval or new Function, call document.write, or load files from hosts outside the asset list. See Interactivity for what to build with CSS instead.

Snippets: render

A theme can keep reusable pieces of Liquid as snippets, a product card used by five sections for example, and render them with {% render 'name' %}. Snippets are managed from the page editor's Snippets panel.

Rendering a snippetliquid
{% comment %} Pass values in by name {% endcomment %}
{% render 'product-card', product: item, show_vendor: true %}
{% comment %} One value, under an alias {% endcomment %}
{% render 'price' with item as product %}
{% comment %} Once per item, with a forloop inside the snippet {% endcomment %}
{% render 'product-card' for products as product %}
RuleDetail
The name is a quoted string{% render 'product-card' %}, never a variable. That lets the editor check that the snippet exists when you save.
A snippet cannot see your variablesIt sees the page’s objects (section, product, settings…) and the arguments you pass. Anything you assigned must be passed in.
Only the theme’s own snippetsA section can never render another theme’s or another store’s snippets.
Depth is limitedSnippets can render snippets, a few levels deep, including recursion for menus.

Tags you cannot use

TagWhy
{% include %}Reaches a filesystem. Use {% render %} with a theme snippet instead.
{% layout %}There is no layout file. A section is one piece of a page.

A section that uses one is rejected when you save it, with the tag named in the error. Shopify's {% form %} and {% section %} do not exist either: forms use the lead-submit widget, and sections are added to pages in the editor.

Still stuck? Our team reads every message.

Need help?