Skip to content
On this page · 23 sections
  1. A section file
  2. Required: the editor attributes
  3. Schema keys
  4. Setting types
  5. Text and numbers
  6. Choices
  7. Media and links
  8. Look
  9. Content
  10. Display only
  11. Empty values
  12. Showing a setting only when it applies
  13. Blocks
  14. Section blocks
  15. Theme blocks
  16. Nested blocks
  17. Static blocks
  18. Hidden blocks
  19. Presets
  20. Limits
  21. Click to edit
  22. Scripts in sections
  23. Translating labels
Docs

Sections and blocks

Updated

How to write sections and theme blocks, the {% schema %} format, every setting type, presets, limits, nested blocks and the attributes the theme editor needs.

Sections are the building blocks owners add, remove and reorder in the theme editor. Blocks are the smaller pieces inside a section, such as a heading, a slide or a column. Each section and theme block is a Liquid file with a {% schema %} that tells the editor what can be changed.

A section file

<section class="feature-list color-{{ section.settings.color_scheme }}" {{ section.in1s_attributes }}>
  {%- if section.settings.heading != blank -%}
    <h2 data-setting-id="heading" data-setting-type="text">{{ section.settings.heading | escape }}</h2>
  {%- endif -%}
  <ul>
    {%- for block in section.blocks -%}
      <li {{ block.in1s_attributes }}>{{ block.settings.title | escape }}</li>
    {%- endfor -%}
  </ul>
</section>

{% schema %}
{
  "name": "t:sections.feature-list.name",
  "tag": "div",
  "settings": [
    { "type": "text", "id": "heading", "label": "t:sections.feature-list.settings.heading.label", "default": "Features" },
    { "type": "color_scheme", "id": "color_scheme", "label": "t:sections.all.color_scheme", "default": "scheme-1" }
  ],
  "blocks": [
    {
      "type": "feature",
      "name": "t:sections.feature-list.blocks.feature.name",
      "settings": [
        { "type": "text", "id": "title", "label": "t:sections.feature-list.blocks.feature.settings.title.label" }
      ]
    }
  ],
  "max_blocks": 12,
  "presets": [
    { "name": "t:sections.feature-list.name", "blocks": [{ "type": "feature" }, { "type": "feature" }] }
  ]
}
{% endschema %}

Each file has exactly one {% schema %}, outside any other tag and comment, holding valid JSON. Name files in lower case with hyphens.

Required: the editor attributes

Print {{ section.in1s_attributes }} on the first element of a section and {{ block.in1s_attributes }} on each block's root element. They are what lets the editor select, highlight and move the section or block. Without them the page still renders, but the section cannot be used in the editor, and the code editor shows a warning. shopify_attributes works as another name for the same thing.

Schema keys

Key Meaning
name The name shown in the editor. Use a t: key to translate it.
settings The section's settings (see Setting types).
blocks The block types the section accepts.
presets Ready-made versions shown in the editor's Add section list. A section with presets can be added and removed by owners; one without presets cannot.
max_blocks The most blocks the section can hold. Default 50.
limit The most times the section can appear in one template or group.
tag The wrapper element: section, div, article, aside, header or footer. Anything else becomes div.
class A CSS class on the wrapper.
group Only allow the section in a section group of this type, for example header. It can then never be added to a template.
enabled_on / disabled_on Where the section may be added: { "templates": ["index", "entry"], "groups": ["footer"] }. Use one or the other.
preview The label the editor shows for one instance, with setting values in braces: "{heading}".
locales Translations of the schema's labels, inline, instead of the locale files.
default Settings and blocks for a section rendered in a fixed place with {% section %}.

Setting types

Every setting has a type, an id (except the two display types), a label and, usually, a default. Optional keys: info (help text under the field), placeholder, and visible_if (see below).

Text and numbers

Type What the owner gets Extra keys
text A single line placeholder
textarea Several lines placeholder
richtext A rich-text editor (paragraphs, lists, links); cleaned when saved
inline_richtext Rich text without block elements, for a heading or a label
html Raw HTML
liquid Liquid code, rendered in place
number A number field
range A slider min, max, step, unit

Choices

Type What the owner gets Extra keys
checkbox An on/off switch default: true or false
select A drop-down options: a list of { "value", "label" }
radio Radio buttons options
checkbox_group Several choices; the value is a list options
text_alignment Left, centre or right
date A date
Type Value in Liquid
image_picker An image from the media library (image is an older name)
video An uploaded video
video_url A YouTube or Vimeo link; accept can be ["youtube", "vimeo"]
url A link. Internal pages are stored as references, so they survive a rename and follow the visitor's language.
link_list A menu

Look

Type Value in Liquid
color A colour
color_background A colour or a gradient
color_scheme One of the theme's colour schemes. Unset, it is the first scheme.
color_scheme_group Defines the colour schemes; used once, in config/settings_schema.json
font_picker A font

See Theme settings and translations for colour schemes and fonts.

Content

Type What it does Extra keys
data_source Picks a data list; the value is the list
field_mapping Picks a field of that list; the value is the field id data_source (the id of the data_source setting), field_types (allowed field types)
entry_picker Picks one entry of that list; the value is the entry data_source
form Picks one of your forms; the value is its handle
{%- assign source = section.settings.data_source -%}
{%- assign image_field = section.settings.image_field -%}
{%- for item in source.entries limit: 6 -%}
  {{ item[image_field] | image_url: width: 600 | image_tag: alt: item.title }}
{%- endfor -%}

Display only

header (a heading in the settings panel) and paragraph (a line of help text) take content instead of id and label.

Empty values

A setting the owner has not set uses its default. Without a default it is nil, which is false in {% if %}. A picker that points to something deleted or unpublished is nil too, so test it before use: {% if section.settings.entry %}.

Showing a setting only when it applies

visible_if hides a setting in the editor unless a condition holds. It uses Liquid comparison syntax and can read section.settings, block.settings and the global settings:

{ "type": "select", "id": "layout", "label": "Layout", "options": [{ "value": "grid", "label": "Grid" }, { "value": "list", "label": "List" }], "default": "grid" },
{ "type": "range", "id": "columns", "label": "Columns", "min": 2, "max": 4, "step": 1, "default": 3, "visible_if": "{{ section.settings.layout == 'grid' }}" }

It supports ==, !=, <, >, <=, >=, contains, blank, empty, and and or. A condition the editor cannot read leaves the setting visible.

Blocks

Section blocks

Blocks declared inside a section's blocks belong to that section. Loop over section.blocks and branch on block.type, or call {% render block %} for each.

{%- for block in section.blocks -%}
  {%- case block.type -%}
    {%- when 'feature' -%}<li {{ block.in1s_attributes }}>{{ block.settings.title | escape }}</li>
  {%- endcase -%}
{%- endfor -%}

Theme blocks

A file in blocks/ is a theme block, usable in any section that accepts @theme. It has its own {% schema %} with name, settings, and optionally blocks, presets, max_blocks, tag, class, enabled_on / disabled_on (by template) and icon (inline SVG, or a file in block-icons/).

<div class="text" {{ block.in1s_attributes }}>{{ block.settings.text }}</div>

{% schema %}
{
  "name": "t:blocks.text.name",
  "settings": [{ "type": "richtext", "id": "text", "label": "t:blocks.text.settings.text.label" }],
  "presets": [{ "name": "t:blocks.text.name" }]
}
{% endschema %}

A section accepts every theme block with "blocks": [{ "type": "@theme" }] and renders them with {% content_for 'blocks' %}. With @theme, the section's own inline block types are not used.

  • Private blocks: a file whose name starts with _ (_slide.liquid) is left out of @theme. A section uses it by naming it: { "type": "_slide" }.
  • Wrapper: a block is wrapped in a div unless its tag says otherwise; "tag": null means no wrapper, and then the block must print {{ block.in1s_attributes }} on its own root element.
  • Variables: inside a block, block, section and the global objects are available.

Nested blocks

A theme block can hold blocks of its own: give it a blocks list (for example [{ "type": "@theme" }]) and print {% content_for 'blocks' %} where its children go. Blocks can nest up to 8 levels below the section.

<div class="group" {{ block.in1s_attributes }}>
  {% content_for 'blocks' %}
</div>

{% schema %}
{
  "name": "t:blocks.group.name",
  "blocks": [{ "type": "@theme" }],
  "presets": [{ "name": "t:blocks.group.name", "blocks": [{ "type": "image" }, { "type": "text" }] }]
}
{% endschema %}

Static blocks

A static block sits at a fixed place in the section's markup. Owners can change its settings and hide it, but not move, duplicate or delete it.

<section {{ section.in1s_attributes }}>
  {% content_for 'block', type: 'heading', id: 'hero-heading' %}
  <div>{% content_for 'blocks' %}</div>
</section>

Declare it in the preset with "static": true and the same id. Static blocks are not listed in block_order, so the preset's blocks is an object:

{
  "presets": [{
    "name": "Hero",
    "blocks": {
      "hero-heading": { "type": "heading", "static": true, "id": "hero-heading", "settings": { "heading": "Welcome" } },
      "text-1": { "type": "text", "settings": {} }
    },
    "block_order": ["text-1"]
  }]
}

Hidden blocks

A block the owner hides is left out of the page for visitors and stays in section.blocks (shown faded) in the editor. section.hidden_blocks lists the hidden ones on the live page.

Presets

A preset is the starting point when an owner adds a section or block: its name, and optionally settings and blocks to start with. A block preset can have a category, which groups it in the editor's block picker.

Limits

  • A template or section group can hold up to 25 sections. The limit is counted separately for each template and each group.
  • A section or block can hold up to 50 blocks unless its max_blocks says otherwise.
  • Blocks can nest up to 8 levels below the section.

Click to edit

Mark the element that shows a text setting with data-setting-id (the setting's id), and with data-setting-type for rich text. In the editor, the owner can then hover it to see which setting it is and type into it on the page.

<h2 data-setting-id="heading" data-setting-type="text">{{ section.settings.heading | escape }}</h2>
<div data-setting-id="body" data-setting-type="richtext">{{ section.settings.body }}</div>

Translations printed with | t are editable in place automatically. Images and links printed from a section's or block's settings are linked to their setting automatically, as long as the element carries the editor attributes.

Scripts in sections

When an owner edits a section, the editor swaps in a freshly rendered copy and fires in1s:section:load on it. Set up any script behaviour again on that event, and never leave content hidden until a script reveals it. See Liquid tags.

Translating labels

Use t: keys for every name, label, info text, option label and preset name, and add them to your default schema locale file, for example locales/en.default.schema.json:

{
  "sections": {
    "feature-list": {
      "name": "Feature list",
      "settings": { "heading": { "label": "Heading" } },
      "blocks": { "feature": { "name": "Feature", "settings": { "title": { "label": "Title" } } } }
    }
  }
}

Theme block labels live under blocks. See Theme settings and translations.

Start typing to search the docs.