Skip to content
On this page · 9 sections
  1. Control flow
  2. Loops
  3. Variables and output
  4. Snippets
  5. Sections and blocks
  6. Styles and scripts
  7. Forms
  8. Pagination
  9. Other tags
Docs

Liquid tags

Updated

The Liquid tags in1s themes support, from if and for to section, render, form, paginate, schema and the asset tags, with the rules that differ from what you may expect.

Tags are the logic of a template, written between {% and %}. in1s supports the standard Liquid tags and the theme tags Shopify themes use, plus a few of its own. Add - inside the delimiters ({%- and -%}) to trim the whitespace around a tag.

Control flow

Tag Use
{% if %} · {% elsif %} · {% else %} · {% endif %} Render when a condition holds
{% unless %} · {% endunless %} Render when a condition does not hold
{% case %} · {% when %} · {% else %} · {% endcase %} Choose by value; when takes several values separated by , or or

Conditions support ==, !=, <>, <, >, <=, >=, contains, and and or, and the special values blank and empty.

Important: Three rules to remember

  • Only nil and false are false. 0, "" and [] are true. Write {% if entry.stock > 0 %} or {% if entry.title != blank %}, not a bare {% if entry.stock %}.
  • Conditions take no filters. {% if index | modulo: 2 == 1 %} tests index alone. Assign first.
  • and and or have no precedence and no parentheses. They group from the right: a or b and c means a or (b and c).
{%- assign row_parity = forloop.index0 | modulo: 2 -%}
{%- if row_parity == 1 -%}<hr>{%- endif -%}

Two strings compare exactly: "1" == "01" is false. When one side is a number written in the template, they are compared as numbers.

Loops

Tag Use
{% for item in list %} · {% else %} · {% endfor %} Repeat for each item; else renders when there is nothing to loop over
{% break %} · {% continue %} Leave the loop, or skip to the next item
{% cycle 'a', 'b' %} Alternate between values on each pass
{% tablerow item in list cols: 3 %} · {% endtablerow %} Table rows and cells
{% ifchanged %} · {% endifchanged %} Render only when the output differs from the last pass

for takes limit:, offset: and reversed, and ranges such as (1..5), which include both ends. Inside a loop, forloop gives index, index0, rindex, rindex0, first, last, length and parentloop.

{%- for entry in data_list.entries limit: 6 -%}
  {% render 'entry-card', entry: entry %}
{%- else -%}
  <p>{{ 'general.no_entries' | t }}</p>
{%- endfor -%}

Variables and output

Tag Use
{% assign name = value %} Set a variable, with filters
{% capture name %} · {% endcapture %} Set a variable to rendered output
{% increment name %} · {% decrement name %} Print and change a counter
{% echo value %} Print a value, mostly inside {% liquid %}
{% liquid %} Several tags on separate lines, without delimiters
{% raw %} · {% endraw %} Print Liquid code without running it
{% comment %} · {% endcomment %} A comment; its content is not run
{% # comment %} A one-line comment; every line of a multi-line one starts with #
{% doc %} · {% enddoc %} A documentation comment for a snippet or block

A {% liquid %} block prints nothing between its lines, so write the spaces you want (echo " "). Avoid %} inside it, even in a comment line: it ends the block.

Snippets

{% render 'name' %} renders snippets/name.liquid. Pass the values it needs as named parameters; they exist only while the snippet renders.

{% render 'entry-card', entry: entry, show_date: true %}

{% render 'card' with value %} passes one value under the snippet's own name (card), and {% render 'card' for list %} renders the snippet once per item, each time with the item as card.

{% include 'name' %} is the older form and works the same way. Prefer render with named parameters.

Note

Pass everything a snippet needs as parameters rather than relying on the caller's variables, and give the snippet's own variables names that will not clash with the caller's.

A snippet that renders itself, directly or through others, is stopped, and a page renders at most 10,000 snippets, sections and blocks in all.

Sections and blocks

Tag Use
{% sections 'header-group' %} Render a section group, usually in the layout
{% section 'name' %} Render one section at a fixed place in a layout
{% content_for 'blocks' %} Render a section's or block's theme blocks, in the owner's order
{% content_for 'block', type: 'heading', id: 'title' %} Render one static block at a fixed place
{% render block %} Render one block from a loop over section.blocks (unquoted block)
{% schema %} · {% endschema %} The section's or block's settings, blocks and presets, as JSON

See Sections and blocks for how they fit together.

{% for block in section.blocks %}
  {% unless forloop.first %}<hr>{% endunless %}
  {% render block %}
{% endfor %}

A static block can receive extra values: {% content_for 'block', type: 'heading', id: 'title', size: 'large' %} makes size available inside the block. Values can be quoted text, numbers or variables.

Styles and scripts

Tag Use
{% style %} · {% endstyle %} CSS printed where the tag is, for each section on the page. Use it for CSS that reads settings.
{% stylesheet %} · {% endstylesheet %} CSS collected from every section into one <style> in the head; identical blocks are printed once
{% javascript %} · {% endjavascript %} JavaScript collected into one <script> before </body>, each block wrapped in its own function; identical blocks are printed once

All three can use Liquid. A value that changes per section makes each copy different, so it is printed once per section; keep stylesheet and javascript free of per-section values.

Theme settings preview live in the editor only from {% style %} blocks; other changes reload the preview.

Tip: Scripts and the theme editor

Your scripts run once per page. When an owner edits a section, the editor replaces that section's element and fires in1s:section:load on the new one (and in1s:section:unload on the old one). If your script sets elements up when the page loads, set the new section up again on in1s:section:load, using event.target. Never hide content until a script shows it without doing this, or edited sections stay blank in the editor. The shopify: event names work too.

{%- javascript -%}
  function setUp(root) { /* … */ }
  setUp(document);
  document.addEventListener('in1s:section:load', function (event) { setUp(event.target); });
{%- endjavascript -%}

Forms

{% form %} renders one of your forms by its handle and handles its submission. Inside the tag, form holds the form, its fields, its errors and whether it was just sent (see Liquid objects).

Assign the handle first. The tag takes a quoted handle or a variable, but no filters. When the handle comes from a setting, assign it (with any fallback) and pass the variable:

{%- assign form_handle = section.settings.form | default: 'contact' -%}
{%- form form_handle, section-id: section.id -%}
  {%- if form.posted_successfully? -%}
    <p role="status">{{ form.success_message | escape }}</p>
  {%- endif -%}
  {%- if form.errors -%}
    <ul role="alert">{%- for error in form.errors -%}<li>{{ error | escape }}</li>{%- endfor -%}</ul>
  {%- endif -%}
  {%- for field in form.fields -%}
    <label for="{{ field.html_id }}">{{ field.label | escape }}</label>
    <input id="{{ field.html_id }}" name="{{ field.name }}" type="{{ field.html_type }}" value="{{ field.value | escape }}">
  {%- endfor -%}
  <button type="submit">{{ form.submit_label | escape }}</button>
{%- endform -%}
  • The form element's id and class are set for you (form_{handle}, dynamic-form dynamic-form--{handle}); your own id: or class: on a user form is ignored.
  • section-id: section.id gives the form a unique id when the same form appears in several sections on one page, and shows the result of a submission only in the section it was sent from.
  • You can show the same form several times on a page. A submission is processed once, and every copy shows the same outcome.
  • A form that no longer exists renders nothing.
  • A form with conditional fields: render a field the server has hidden as hidden and disabled, so a visitor without JavaScript can still submit. The Blank theme's snippets/form-fields.liquid does this for every field type; reuse it.

Two built-in forms:

{% form 'localization' %}
A language switcher. Post a language_code field; the visitor returns to the same page in the chosen language. Accepts id: and class:.
{% form 'storefront_password' %}
The password field on layout/password.liquid. Post a password field; form.errors is set when it was wrong.
{%- if localization.available_languages.size > 1 -%}
  {%- form 'localization', class: 'language-switcher' -%}
    <select name="language_code">
      {%- for language in localization.available_languages -%}
        <option value="{{ language.iso_code }}"{% if language.iso_code == localization.language.iso_code %} selected{% endif %}>{{ language.endonym_name }}</option>
      {%- endfor -%}
    </select>
    <button type="submit">{{ 'general.language_change' | t }}</button>
  {%- endform -%}
{%- endif -%}

Pagination

{% paginate %} pages a data list's entries or the search results:

{%- paginate data_list.entries by 12 -%}
  {%- for entry in data_list.entries -%}
    {% render 'entry-card', entry: entry %}
  {%- endfor -%}
  {{ paginate | default_pagination }}
{%- endpaginate -%}

by sets the page size inside the block, from 1 to 250. window_size: (default 2) sets how many page numbers show on each side of the current one. Inside, paginate gives current_page, current_offset, items, page_size, pages, previous and next (each with title, url, is_link) and parts (the page links, with gaps). Page links keep the visitor's sort and filters.

It works on data_list.entries, on a list reached by handle (data_lists['posts'].entries) and on search.results. All paged lists on one page read the same ?page=.

Other tags

Tag Use
{% extends 'name' %} · {% block name %} Template inheritance: a file extends another and replaces its named blocks. Not part of Shopify Liquid.
{% appembeds %} Accepted for compatibility with Shopify themes; renders nothing

A tag the engine does not know is an error, which the code editor reports when you save.

Start typing to search the docs.