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
| Tag | What 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.
Scope every selector
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.
| Rule | Why |
|---|---|
| Run your code straight away | The 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.id | There can be two copies of your section on a page. A global querySelector finds the wrong one. |
| Do not bind twice | Scripts run again when a shopper comes back to the page. Mark the element once bound, as above. |
| Page sections, header and footer only | Scripts do not run in the cart drawer, quick add or checkout templates. |
| Keep it short and readable | Every 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.
| Rule | Detail |
|---|---|
| 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 variables | It 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 snippets | A section can never render another theme’s or another store’s snippets. |
| Depth is limited | Snippets can render snippets, a few levels deep, including recursion for menus. |
Tags you cannot use
| Tag | Why |
|---|---|
| {% 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.
Related guides