Theme Section Blocks
How to design, render, and edit section blocks in Cartly themes. Reference for theme authors and agency partners building reusable section components.
Overview
A section is a top-level unit of a page template — a hero, a featured-collection grid, a footer. Sections have their own .liquid file, their own {% schema %} block, and their own settings panel in the visual editor. Merchants can add, remove, and reorder sections via the editor's left section list.
A block is a sub-unit within a section: one card in an editorial pair, one column in a footer navigation, one panel in a product accordion. Blocks exist because sections often need repeating UI of variable count where each repetition can carry different content — and where the structure is tightly coupled to the section's layout, so it makes no sense to reorder blocks independently of their parent section.
This guide is the canonical reference for:
- How to declare blocks in a section's
{% schema %} - How the instance JSON ends up shaped in
templates/*.json - How to render blocks in Liquid
- What the visual editor lets merchants do vs. what stays in the code editor
- How to design sections that reuse cleanly across themes
When to use a block vs. a setting vs. a separate section?
Use a setting for a single toggle / colour / heading. Use a block for repeating UI inside one section where structure is fixed by the theme author (footer columns, accordion panels, marquee items). Use a separate section for content the merchant might add or remove independently (hero, featured collection, blog posts).
Schema Declaration
Section schemas declare which block types the section accepts, what fields each block carries, and optional limits.
{% schema %}
{
"name": "Editorial pair",
"class": "clarity-editorial-pair-section",
"max_blocks": 2,
"blocks": [
{
"type": "card",
"name": "Card",
"settings": [
{ "type": "text", "id": "eyebrow", "label": "Eyebrow", "default": "The Materials" },
{ "type": "text", "id": "heading", "label": "Heading", "default": "Sourced from twelve small mills across Europe." },
{ "type": "textarea", "id": "body", "label": "Body" },
{ "type": "image_picker", "id": "image", "label": "Background image" },
{ "type": "url", "id": "cta_url", "label": "CTA link" },
{
"type": "select", "id": "color_scheme", "label": "Color scheme", "default": "dark",
"options": [
{ "value": "light", "label": "Light" },
{ "value": "dark", "label": "Dark" }
]
}
]
}
],
"presets": [
{ "name": "Editorial pair", "blocks": [
{ "type": "card", "settings": { "eyebrow": "The Materials", "heading": "Sourced from twelve small mills." } },
{ "type": "card", "settings": { "eyebrow": "The Craft", "heading": "Made in workshops we know by name." } }
]}
]
}
{% endschema %}Fields in a block schema entry:
type— discriminator. Used in{% if block.type == 'card' %}in Liquid.name— display label in the visual editor accordion header.settings— array of fields (same shape as section settings).limit— optional per-type maximum count.
Section-level controls related to blocks:
max_blocks— total cap across all block types.blocks— array of allowed block types.presets[].blocks— pre-populated blocks when the merchant adds the section.
Instance JSON Shape
Section instances live in templates/*.json (or in sections/<name>-group.json for layout-zone sections — header, footer). The blocks-related fields are blocks (a keyed map) and block_order (an array of keys controlling render order).
// templates/index.json — section instance with blocks map + block_order
{
"sections": {
"editorial": {
"type": "editorial-pair",
"id": "editorial",
"visible": true,
"settings": {},
"blocks": {
"card-materials": {
"type": "card",
"settings": {
"eyebrow": "The Materials",
"heading": "Sourced from twelve small mills across Europe.",
"body": "Italian linen, Portuguese cotton, Scottish merino.",
"image": "/uploads/products/materials.jpg",
"cta_url": "/pages/materials",
"color_scheme": "light"
}
},
"card-craft": {
"type": "card",
"settings": {
"eyebrow": "The Craft",
"heading": "Made in workshops we've visited twice a year.",
"cta_url": "/pages/craft",
"color_scheme": "dark"
}
}
},
"block_order": ["card-materials", "card-craft"]
}
},
"order": ["editorial", "..."]
}Cartly's canonical key is block_order (singular, matches Shopify). The visual editor reads either key for backwards compatibility with in-flight drafts but always writes the singular form on next save.
Block keys (card-materials, card-craft in the example above) are merchant-facing identifiers. They can be any unique string within the section; Cartly itself doesn't parse them. Convention: prefix with the block type, suffix with a content-derived slug (e.g. card-<slug>).
Liquid Rendering
Inside a section's .liquid file, iterate section.blocks. The renderer assembles this array from the instance's blocks map in block_order; any blocks not in block_order are appended at the tail (lossless fallback).
{# sections/editorial-pair.liquid #}
<section class="editorial-pair" data-section-id="{{ section.id }}">
<div class="editorial-pair__grid">
{%- for block in section.blocks -%}
{%- if block.type == 'card' -%}
{%- assign scheme = block.settings.color_scheme | default: 'dark' -%}
<article class="editorial-card editorial-card--{{ scheme }}"
{{ block.shopify_attributes }}>
{%- if block.settings.image != blank -%}
<img src="{{ block.settings.image | image_url: width: 1400 | escape }}"
alt="{{ block.settings.image.alt | default: block.settings.heading | escape }}"
loading="lazy">
{%- endif -%}
<p class="eyebrow">{{ block.settings.eyebrow | escape }}</p>
<h2 class="heading">{{ block.settings.heading | escape }}</h2>
{%- if block.settings.body != blank -%}
<p class="body">{{ block.settings.body | escape }}</p>
{%- endif -%}
{%- if block.settings.cta_url != blank -%}
<a class="cta" href="{{ block.settings.cta_url | escape }}">Read more →</a>
{%- endif -%}
</article>
{%- endif -%}
{%- endfor -%}
</div>
</section>Key patterns:
- Discriminate on
block.typeif your section accepts multiple types (e.g.card+promo_tile). - Access values via
block.settings.<key>. - Emit
{{ block.shopify_attributes }}on the block's outer element. This injectsdata-block-id="X", which the visual editor'scartly:block:selectbridge uses to scroll to and highlight the matching block when a merchant expands its accordion in the right panel. - Apply
| escape(or| image_url | escape) per the M-6 attribute escape rule in THEME-AUTHORING-STANDARDS.
Presets
Presets pre-populate blocks when a merchant adds the section to a page. Without presets, a merchant adds the section and sees an empty container — bad UX.
Each preset declares an array of blocks with their initial settings. The Visual Editor's + Add section picker shows one entry per preset; selecting one creates the section with the preset's blocks already in place.
Rule of thumb: every block-driven section should ship at least one preset with default content matching the theme's design (verbatim copy from your mockup). Empty placeholders are an anti-pattern — see S-2 in THEME-AUTHORING-STANDARDS.
Reuse Across Themes
Three patterns for sharing a section across multiple themes:
- Boilerplate inheritance (recommended for first-party themes). Place the section
.liquidand any shared snippets inbackend/internal/theme/templates/boilerplate/. The 3-layer resolver (DB → theme → boilerplate) lets each theme override only what differs while the shared base lives in one place. - Copy-paste with versioning. Acceptable for theme-partner work where two themes have distinct designs but share a structural component (e.g. an FAQ accordion). Drift is expected — re-sync intentionally on major releases.
- Marketplace theme extension (planned, out of scope for current release). A section ships as a third-party app block and installs via the App Store.
Code Editor: Structural Changes
Merchants add, duplicate, delete and reorder blocks in the visual editor (see below). The code editor (/admin/themes/<id>/code) edits the same instance JSON directly — for anything the visual editor does not offer (changing a block's type, app blocks, per-block visibility).
Operations:
- Add a block: add an entry to
sections.<id>.blockswith a unique key, type, and settings; push the same key tosections.<id>.block_order. - Remove a block: delete the key from
blocksAND remove it fromblock_order. Both required — leaving a tail inblock_orderfor a missing key is a no-op (filtered out at render), leaving the block in the map without an order entry appends it at the tail. - Reorder: rearrange the
block_orderarray. - Visibility: not supported per-block in the current renderer. Use a conditional
{% if block.settings.show %}inside the Liquid loop instead, paired with a checkbox setting on the block.
Visual Editor: Merchant Surface
In the visual editor's right panel, when a merchant clicks a section whose schema declares blocks, an accordion appears below the section settings:
- One row per block in
block_order - Header shows the block type's display name (from
schema.blocks[].name) - Expanding a row reveals the block's settings rendered through the same field renderer as section settings (image_picker, color, text, select, etc.)
- The accordion is lazy-mounted — only the expanded row's settings tree exists in the DOM. Sections with 20+ blocks containing
image_pickerorrichtextstay responsive. - Expanding a row also triggers a
cartly:block:selectpostMessage to the iframe preview, which scrolls to and pulses the matching[data-block-id]element. The theme must emit{{ block.shopify_attributes }}on the block's outer markup for this to work.
- Add block lists the block types the section schema declares (
@app/@themeentries are not offered); a new block starts with its type's settingdefaults. The schema'smax_blocksand each type'slimitare enforced — past them Add / Duplicate are disabled with the reason. - Each row can be duplicated (a copy under a fresh id right after it), deleted (with Undo), and reordered — drag the grip, use the keyboard (Space / Enter on the grip, arrow keys, Space / Enter to drop, Escape to cancel) or the up / down buttons.
- Writes keep the section's storage shape: a
blocksmap stays a map withblock_order, an array stays an array. - A block whose type the section schema does not describe (e.g. an app block) is listed, movable and deletable; its settings are not editable there.
What merchants cannot do in the visual editor: toggle a block's visibility or change its type.
Best Practices
- Always ship a preset. Empty placeholder UI is the most common source of merchant confusion. The preset should match the mockup's default state verbatim.
- Pair
max_blockswith the Liquid template's UI capacity. Editorial-pair hasmax_blocks: 2because its CSS grid is two-column. A marquee withmax_blocks: 20can run unbounded because the layout is a scroll loop. - Use blocks for repeating UI with different content. Use settings for a fixed UI control. Use separate sections for things the merchant might add or remove independently.
- Don't nest blocks. Cartly Liquid (matching Shopify) does not support blocks-within-blocks. The parser logs a
console.warnif it finds a nestedblockskey under a block type, but the inner blocks are ignored. If you need hierarchical content, use JSON arrays inside a single block's settings (e.g. footer column with"links": [{"label":"…","url":"…"}, ...]as a single textarea or richtext field, parsed in Liquid). - Emit
{{ block.shopify_attributes }}. Required for the visual editor's block highlight bridge. - Apply
| escapeto all merchant-controlled attribute interpolations. See THEME-AUTHORING-STANDARDS M-6.
Full Example: Footer Link Columns
Footer is the canonical "many blocks, one block type" case. Each column is a link_column block with a heading and a menu handle. The merchant edits the heading and which Cartly menu to bind to; structure (number of columns, order) is set by the theme author.
Schema
{% schema %}
{
"name": "Footer",
"class": "site-footer-section",
"max_blocks": 4,
"settings": [
{ "type": "text", "id": "brand_text", "label": "Brand name", "default": "Cartly" }
],
"blocks": [
{
"type": "link_column",
"name": "Link column",
"settings": [
{ "type": "text", "id": "heading", "label": "Heading", "default": "Shop" },
{ "type": "link_list", "id": "menu", "label": "Menu handle", "default": "footer" }
]
}
],
"presets": [
{ "name": "Footer", "blocks": [
{ "type": "link_column", "settings": { "heading": "Shop", "menu": "main-menu" } },
{ "type": "link_column", "settings": { "heading": "Help", "menu": "help" } },
{ "type": "link_column", "settings": { "heading": "Company", "menu": "company" } }
]}
]
}
{% endschema %}Liquid
{# sections/footer.liquid #}
<footer class="site-footer" data-section-id="{{ section.id }}">
<div class="site-footer__brand">
<p>{{ section.settings.brand_text | escape }}</p>
</div>
<nav class="site-footer__columns">
{%- for block in section.blocks -%}
{%- if block.type == 'link_column' -%}
{%- assign menu_handle = block.settings.menu | default: 'main-menu' -%}
<div class="site-footer__column" {{ block.shopify_attributes }}>
<h3 class="site-footer__heading">{{ block.settings.heading | escape }}</h3>
{%- if linklists[menu_handle].links.size > 0 -%}
<ul>
{%- for link in linklists[menu_handle].links -%}
<li><a href="{{ link.url | escape }}">{{ link.title }}</a></li>
{%- endfor -%}
</ul>
{%- endif -%}
</div>
{%- endif -%}
{%- endfor -%}
</nav>
</footer>Instance JSON (after merchant install)
{
"footer": {
"type": "footer",
"settings": { "brand_text": "Cartly" },
"blocks": {
"col-shop": { "type": "link_column", "settings": { "heading": "Shop", "menu": "main-menu" } },
"col-help": { "type": "link_column", "settings": { "heading": "Help", "menu": "help" } },
"col-company": { "type": "link_column", "settings": { "heading": "Company", "menu": "company" } }
},
"block_order": ["col-shop", "col-help", "col-company"]
}
}Merchant edits in the visual editor: change "Shop" → "Boutique", pick a different menu handle. The block's settings object updates;block_order stays the same. Adding a 4th column or reordering them is done in the code editor.
Cross-References
- Clarity Theme guide — overall theme architecture, design tokens, fork-on-write workflow
- Section Groups guide — header-group / footer-group layout zones and where to declare them in
layouts/theme.liquid - THEME-AUTHORING-STANDARDS (in repo at
docs/THEME-AUTHORING-STANDARDS.md) — M-1 (data-section-id), M-5 (escapeHtml), M-6 (attribute escape), and other gating rules for new theme PRs