Building Custom Sections and Blocks in Shopify Online Store 2.0

Building Custom Sections and Blocks in Shopify Online Store 2.0

The best Shopify themes give merchandisers freedom without letting them break the design. In Online Store 2.0, that freedom comes from sections and blocks: reusable components with their own settings that can be added to any JSON template from the theme editor. Here is how we build them.

How sections work

A section is a Liquid file in the sections/ folder. It contains markup plus a {% schema %} tag that tells the theme editor which settings and blocks it supports. Templates such as templates/product.json list which sections appear and in what order, so merchants can rearrange pages without touching code.

A real example: a feature grid

This section renders a heading and up to six features, each with an image, title and rich text. Merchants can add, remove and reorder features in the editor.

{%- comment -%} sections/feature-grid.liquid {%- endcomment -%}
<section class="feature-grid page-width">
  {%- if section.settings.heading != blank -%}
    <h2 class="feature-grid__heading">{{ section.settings.heading | escape }}</h2>
  {%- endif -%}

  <div class="feature-grid__items">
    {%- for block in section.blocks -%}
      <div class="feature-grid__item" {{ block.shopify_attributes }}>
        {%- if block.settings.image != blank -%}
          {{ block.settings.image | image_url: width: 600 | image_tag: loading: 'lazy', widths: '300, 450, 600' }}
        {%- endif -%}
        <h3>{{ block.settings.title | escape }}</h3>
        {{ block.settings.text }}
      </div>
    {%- endfor -%}
  </div>
</section>

{% schema %}
{
  "name": "Feature grid",
  "tag": "section",
  "class": "section",
  "settings": [
    { "type": "text", "id": "heading", "label": "Heading", "default": "Why customers choose us" }
  ],
  "blocks": [
    {
      "type": "feature",
      "name": "Feature",
      "settings": [
        { "type": "image_picker", "id": "image", "label": "Image" },
        { "type": "text", "id": "title", "label": "Title", "default": "Free 30-day returns" },
        { "type": "richtext", "id": "text", "label": "Text" }
      ]
    }
  ],
  "max_blocks": 6,
  "presets": [
    {
      "name": "Feature grid",
      "blocks": [ { "type": "feature" }, { "type": "feature" }, { "type": "feature" } ]
    }
  ]
}
{% endschema %}

Why each piece matters

  • block.shopify_attributes lets the theme editor highlight and select the block when a merchant clicks it.
  • image_url with image_tag generates a correctly sized, lazy-loaded image from Shopify’s CDN instead of the original upload.
  • escape on plain-text settings prevents broken markup if someone types special characters.
  • presets make the section available under Add section, with three blocks ready to edit.
  • max_blocks keeps the layout within what the design can handle.

Our rules for maintainable sections

  1. One job per section. A feature grid, a testimonial slider and an FAQ should be three sections, not one giant section with toggles.
  2. Use theme-wide settings for brand values. Colours and typography belong in config/settings_schema.json and colour schemes, not in every section.
  3. Prefer metafields for product data. If content belongs to a product — care instructions, specs, size guides — store it in a metafield and connect it with a dynamic source rather than typing it into a section.
  4. Load assets per section. Use {% stylesheet %} or a section-specific asset so CSS ships only where it is used.
  5. Keep themes in Git. Shopify’s GitHub integration and the Shopify CLI (shopify theme dev, shopify theme push) make reviews and rollbacks easy.

The result

A library of well-built sections means your marketing team can launch campaign pages in an afternoon, and your developers can spend their time on features rather than copy changes.

Need a custom theme or a section library for your existing one? Our Shopify developers build them every week.

Sources

Need a hand?

Stuck on a build?
Let's solve it together.

Our engineers fix, upgrade and scale Magento, WordPress and modern stacks every day.