Start building

Blog

Shopify section vs snippet vs block: one feature, built each way

The definitions are easy to find and hard to apply. So take one small feature, a shipping note on a product page, and see what changes depending on where it lives.

The Klorr teamUpdated 9 min read

  • Theme architecture
  • Sections
  • Snippets
  • Theme blocks

Key takeaways

  • The question to ask is who changes this. Merchants in the editor need a section or block. Only developers means a snippet is enough.
  • A snippet takes variables from the code that calls it and doesn't appear in the editor. A theme block appears in the editor and can't take ordinary variables from its parent.
  • One section can't mix section blocks and theme blocks. A section's schema uses one kind or the other.
  • A section you plan to move between themes should avoid relying on that theme's snippets, or it breaks on arrival.

Say a store wants this line under the buy button on every product: "Free returns within 30 days." It's about as small as a theme feature gets. That one sentence can live in at least four different places, and each one changes who can edit it, where it can go, and what breaks later.

As a snippet: reusable, but only for developers

snippets/returns-note.liquid
{% doc %}
  Short returns line under the buy button.
  @param {number} days - Length of the returns window
{% enddoc %}
<p class="returns-note">Free returns within {{ days }} days.</p>
section.liquid
{%- comment -%} Anywhere in a section or another snippet {%- endcomment -%}
{% render 'returns-note', days: 30 %}

Now the line can appear in the product section, the quick view and a featured product, with one file to change. A snippet can't see variables created outside it, except global objects and what you pass in, and it never appears in the theme editor. So to change "30 days" to "60 days", somebody edits code. That's fine for a markup pattern like a product card or an icon. It's wrong for words a merchant will want to change.

As a section block: editable, but stuck in one section

section.liquid
{%- comment -%} Inside the product section's case block.type {%- endcomment -%}
{%- when 'returns_note' -%}
  <p class="returns-note" {{ block.shopify_attributes }}>{{ block.settings.text | escape }}</p>
schema.json
{
  "type": "returns_note",
  "name": "Returns note",
  "limit": 1,
  "settings": [
    { "type": "text", "id": "text", "label": "Text", "default": "Free returns within 30 days." }
  ]
}

The merchant now edits the wording, drags the note above or below the price, or hides it, with no code. But the block is defined inside this one section's schema, so it exists only there. Featured Product can't use it without copying the same code and schema across. Section blocks also support just one level, so a block can't hold other blocks. This is how Dawn's product section works: its text, price, buy buttons and pop-up are all local blocks.

Adding it means editing the theme's own product section, too. As the Dawn customization guide explains, that's the kind of edit that can conflict when the theme updates.

As a theme block: editable and shared

blocks/returns-note.liquid
<p class="returns-note" {{ block.shopify_attributes }}>{{ block.settings.text | escape }}</p>

{% schema %}
{
  "name": "Returns note",
  "settings": [
    { "type": "text", "id": "text", "label": "Text", "default": "Free returns within 30 days." }
  ],
  "presets": [
    { "name": "Returns note" }
  ]
}
{% endschema %}

A theme block is its own file in blocks/, and any section that accepts theme blocks can use it. The section declares { "type": "@theme" } in its schema's blocks array and places {% content_for 'blocks' %} where they should render. Theme blocks can nest inside each other, up to 8 levels below the section, so a "group" block can hold text and buttons as columns. A theme can hold at most 300 of these files.

The catch is compatibility. Theme blocks need a section built to accept them, and they can't be used in the same section as section blocks. Dawn's product section uses local blocks, so a blocks/ file won't appear there unless that section is rewritten. Check your theme's schema before planning around this.

There's one more variation. A section can also place a theme block in a fixed spot with {% content_for 'block', type: 'returns-note', id: 'returns' %}. That's a static block: merchants can hide it and edit its settings, but can't move or delete it. Static blocks are also the one case where a block gets values from its parent, since extra parameters on the tag reach the block's code.

As a whole section: it can go on any page

Finally, the note can be its own section: a file in sections/, added through Add section. It can go on any template, including pages with no product. But it can't sit between the price and the buy button, because a section can't enter the middle of another section. Sections are the top-level items on a page. A JSON template or section group holds up to 25, and each section holds up to 50 blocks.

For our returns line, a section is overkill. For a full-width band repeated across pages, or anything with its own layout and background, it's the right size. It also needs a `presets` entry to appear in the picker, the same requirement theme blocks have.

The decision table

SnippetSection blockTheme blockSection
Lives insnippets/A section's schemablocks/sections/
Merchant edits in the editorNoYesYesYes
Merchant can move itNoWithin its sectionWithin sections that accept itAround the page
Reused across sectionsYesNo, only by copyingYesNo, but placed on many pages
Takes variables from the callerYesIt's inline, so it sees the section's variablesOnly static blocks, through content_forNo
Can hold othersCan call snippetsNoYes, up to 8 levelsBlocks
Has a schemaNoPart of the section'sYesYes
Called withrenderA for over section.blockscontent_forA JSON template, a group, or section

Going through the questions in order will settle nearly every case:

  1. Does a merchant need to change or move it? If no, use a snippet, or write it directly in the file if it's used once.
  2. Does it make sense on its own, full width, on a page? If yes, it's a section.
  3. Does it go inside an existing section? If yes, it's a block. Check that section's schema: if it lists @theme, make a theme block, and otherwise add a local block.
  4. Will you build a new section that holds configurable pieces? On a theme that supports theme blocks, prefer them when you want to reuse the pieces. If the pieces only make sense here (an FAQ's question, a slide), local blocks are simpler.

They aren't rivals: a product card uses both

Shopify's own docs give the example of a product card that combines them. The block owns what merchants choose (which product, which size). The snippet owns the markup, so the same card can appear in search results too. Dawn does the snippet half of this: snippets/card-product.liquid is rendered from Featured Collection, the collection grid and others, each passing its own options.

blocks/product-card.liquid
{%- comment -%} The block has the settings. The snippet has the markup. {%- endcomment -%}
<div {{ block.shopify_attributes }}>
  {% render 'card-product', card_product: block.settings.product, show_vendor: block.settings.show_vendor %}
</div>

{% schema %}
{
  "name": "Product card",
  "settings": [
    { "type": "product", "id": "product", "label": "Product" },
    { "type": "checkbox", "id": "show_vendor", "label": "Show vendor", "default": false }
  ],
  "presets": [ { "name": "Product card" } ]
}
{% endschema %}

Mix-ups that cost people an afternoon

  • Putting a {% schema %} in a snippet and expecting settings. Snippets don't appear in the editor. A schema only means something in a section or a theme block file.
  • Expecting a variable set in a section to appear inside a snippet. Pass it: {% render 'x', title: title %}. The section object is available in snippets, so section.settings can be read without passing it.
  • Using {% include %} because an old tutorial did. New theme code should use render, and you can't use include inside a snippet rendered with render.
  • Forgetting {{ block.shopify_attributes }}. The block still renders, but clicking it in the preview won't open its settings. See how to add blocks.
  • Hard-coding a snippet name in a section you plan to sell or reuse. On another theme that snippet doesn't exist, and you'll see a Liquid error where it should render.

That last one explains why sections you buy or generate tend to arrive as a single, self-contained .liquid file, with their CSS, JavaScript and schema inside. A Klorr section works this way so it can be dropped into any Online Store 2.0 theme, and the marketplace follows the same format. Inside your own theme, the balance tips the other way: splitting repeated markup into snippets saves you from fixing the same thing in eight places.

Questions, answered

What is the difference between a section and a snippet in Shopify?

A section is a top-level, merchant-customizable part of a page, with a schema that creates settings in the theme editor. A snippet is reusable code rendered by other files. Merchants can't see or edit snippets in the editor.

What is the difference between a section block and a theme block?

A section block is defined inside one section's schema and works only there, one level deep. A theme block is its own file in blocks/, can be used by any section that accepts theme blocks, and can nest up to 8 levels. A section can't mix the two.

Can I use a snippet inside a section?

Yes, it's very common. Use {% render 'name', variable: value %}. The snippet can read global objects and section, plus whatever you pass it. Variables you create inside it stay inside it.

Does Dawn support theme blocks?

Dawn's product section uses local section blocks, so check any section's schema to see which it accepts. If its blocks array includes @theme, it takes theme blocks.

How many blocks and sections can a template have?

Per Shopify's docs, a JSON template or section group can render up to 25 sections, and each section can have up to 50 blocks. A theme can hold at most 300 theme block files.

Get the whole section written for you

Describe the section you want. Klorr writes the Liquid, the CSS, the schema and every theme-editor setting — code that lives in your theme and stays yours.