MyShopy Help Center
Help Center › Themes & templates

Building sections

Write a custom section with Liquid, CSS and a schema, step by step.

A section is three things stored together:

PartPurpose
LiquidThe HTML template. Reads its configuration from section.settings and section.blocks.
CSSStyles for this section only. Loaded once per page wherever the section is used.
Schema (JSON)The settings and blocks merchants see in the editor, plus presets.

Create one in Online Store → ⋯ → Edit code → Sections → +, or over MCP with save_section_code.

A complete example: "Feature highlights"#

Liquid

<div class="section-pad" style="background: {{ section.settings.bg }}">
  <div class="container">
    {%- if section.settings.title != blank -%}
      <h2 class="h-lg" style="text-align:center">{{ section.settings.title | escape }}</h2>
    {%- endif -%}
    <div class="highlights" style="--cols: {{ section.settings.columns }}">
      {%- for block in section.blocks -%}
        <div class="highlight" {{ block.shopify_attributes }}>
          {%- if block.settings.image != blank -%}
            <img src="{{ block.settings.image | image_url: width: 160 }}" alt="" loading="lazy" width="56" height="56">
          {%- endif -%}
          <h3>{{ block.settings.heading | escape }}</h3>
          <div class="rte">{{ block.settings.text }}</div>
        </div>
      {%- endfor -%}
    </div>
  </div>
</div>

CSS

.highlights { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: var(--grid-gap); margin-top: 2rem; }
.highlight { text-align: center; padding: 1.5rem; border: 1px solid var(--color-border); border-radius: var(--radius); }
.highlight img { margin: 0 auto 1rem; border-radius: 50%; }
@media (max-width: 749px) { .highlights { grid-template-columns: 1fr; } }

Schema

{
  "name": "Feature highlights",
  "category": "Text",
  "settings": [
    { "type": "text", "id": "title", "label": "Heading", "default": "Why shop with us" },
    { "type": "range", "id": "columns", "label": "Columns", "min": 2, "max": 4, "step": 1, "default": 3 },
    { "type": "color", "id": "bg", "label": "Background" }
  ],
  "blocks": [
    {
      "type": "highlight",
      "name": "Highlight",
      "settings": [
        { "type": "image_picker", "id": "image", "label": "Icon" },
        { "type": "text", "id": "heading", "label": "Heading", "default": "Free delivery" },
        { "type": "richtext", "id": "text", "label": "Text", "default": "<p>On all orders above ₹999.</p>" }
      ]
    }
  ],
  "max_blocks": 8,
  "presets": [
    { "name": "Feature highlights", "blocks": [ { "type": "highlight" }, { "type": "highlight" }, { "type": "highlight" } ] }
  ]
}

Save it, open the visual editor, click Add section and choose Feature highlights.

Schema reference#

KeyRequiredMeaning
nameyesName shown in the editor
categorynoGroup in the Add section picker (e.g. Banners, Products, Text, Media)
settingsnoSection settings, see Setting types
blocksnoBlock types: { type, name, settings, limit? }
max_blocksnoMaximum number of blocks
presetsnoMakes the section appear in Add section. The first preset's settings and blocks are used when it's added

Liquid objects inside a section#

ObjectContains
section.idUnique id of this section instance
section.settings.<id>Setting values (schema default used when not set)
section.blocksArray of blocks in order: block.id, block.type, block.settings
block.shopify_attributesAlways output this on each block's root element. It lets the editor highlight and select the block.

Every global object (Liquid reference) is available too: shop, settings, cart, product, collections…

Rules and tips#

  • Keep styles scoped: prefix classes with the section name (.highlights, not .grid).
  • Use theme variables like var(--color-accent) and var(--radius) so the section follows the merchant's theme settings (list).
  • Use the shared classes: section-pad, container, h-sm|md|lg|xl, rte, product-grid (with --cols / --cols-m), btn btn--primary|secondary, btn--lg, btn--block.
  • Escape plain text with | escape. richtext and html settings are already HTML.
  • Images: {{ image | image_url: width: 800 }} returns a CDN URL at that width. Always set width/height or aspect-ratio to avoid layout shift.
  • JavaScript (optional js field, MCP/import only) runs once per page. Listen for sf:section:load if the section must re-initialise after an editor change.
  • Liquid is validated on save. Rendering is sandboxed with loop and time limits, so a broken section can't take the store down.
  • Overriding a built-in (e.g. header) stores your version in the theme. Revert to default restores the original.
Didn’t find what you need?Contact support