Build a Shopify theme from scratch, with Liquid · Part 3 of 6
Sections, blocks and the theme editor
Theme and section settings of every type, the font picker with font_face, font_modify and preloads, section blocks for Shop by collection, theme blocks in blocks/ rendered with content_for, a newsletter from form 'customer', the home page as JSON, and the editor.
By Abhishek Fouzdar
This part is about the merchant. Everything so far was fixed in Liquid; after this part a merchant can rearrange the home page, swap the fonts, pick which collections to show and change the words in every band, from the theme editor and without reading a line of code. The pieces are theme settings, section settings of every type, section blocks, the blocks/ directory for theme blocks, the font picker, and a home page built from five sections. Part 2 taught Liquid on the product and collection pages.

Two kinds of settings
A theme has settings in two places, and the difference is scope.
Theme settings live in config/settings_schema.json and apply everywhere. The colours from part 1 are theme settings; Liquid reads them as settings.color_accent. The merchant edits them under Theme settings in the editor, and the values are saved into config/settings_data.json.
Section settings live in the {% schema %} of a section file and apply to one instance of that section. Two Featured collection sections on the same page have two independent sets of values. Liquid reads them as section.settings.heading, and the values are saved into the JSON template the section sits in.
Both use the same input types. The ones this part adds, and what Liquid gets back from each:
| Type | What the merchant sees | What Liquid gets |
|---|---|---|
text, textarea |
A field | A string; escape it on output |
richtext |
A small editor with bold, italic, links, lists | HTML in <p> tags; output it as is |
inline_richtext |
The same, without paragraphs | HTML without block tags, for headings |
image_picker |
The store's Files | An image object, for image_url |
url |
A picker of pages, collections and products, or a typed URL | A string |
collection, product |
A picker | The object itself, not a handle |
collection_list, product_list |
A picker of several | An array of objects |
select |
A dropdown | The chosen option's value |
range |
A slider with min, max, step, unit |
A number |
checkbox |
A checkbox | true or false |
color |
A colour picker | A colour object that prints as a hex string |
font_picker |
Shopify's font library | A font object |
link_list |
The store's menus | A linklist object |
Two more types are not inputs at all: header and paragraph put a title and a line of help text in the sidebar, which is how the Typography group below explains itself.
The font picker
The design wants Manrope for headings and Inter for the body. Both are in Shopify's font library, which is the only place a font_picker draws from, and the library serves them from Shopify's own CDN, so there is no Google Fonts request and no font file in the theme. Two settings in a new Typography group:
{
"name": "Typography",
"settings": [
{ "type": "header", "content": "Fonts" },
{ "type": "paragraph", "content": "Fonts come from Shopify's library and are served from its CDN. System fonts load nothing." },
{ "type": "font_picker", "id": "font_heading", "label": "Headings", "default": "manrope_n7" },
{ "type": "font_picker", "id": "font_body", "label": "Body", "default": "inter_n4" },
{ "type": "range", "id": "heading_scale", "label": "Heading size", "min": 80, "max": 120, "step": 5, "unit": "%", "default": 100 }
]
}
The default is a font handle: family, then n for normal or i for italic, then the weight divided by a hundred. manrope_n7 is Manrope at 700. The handle list is in the font library docs and Theme Check does not validate it, so a typo here shows up as the fallback font and nothing else.
The layout turns the two settings into CSS. This block replaces the <style> from part 1 and sits above content_for_header, so that on a streamed page the browser meets the fonts before the sections:
{%- liquid
assign heading_font = settings.font_heading
assign heading_font_heavy = heading_font | font_modify: 'weight', '+100'
assign body_font = settings.font_body
assign body_font_bold = body_font | font_modify: 'weight', 'bold'
assign body_font_italic = body_font | font_modify: 'style', 'italic'
-%}
{%- unless heading_font.system? and body_font.system? -%}
<link rel="preconnect" href="https://fonts.shopifycdn.com" crossorigin>
{%- endunless -%}
{%- unless heading_font.system? -%}{{ heading_font | font_url | preload_tag: as: 'font', type: 'font/woff2' }}{%- endunless -%}
{%- unless body_font.system? -%}{{ body_font | font_url | preload_tag: as: 'font', type: 'font/woff2' }}{%- endunless -%}
{% style %}
{{ heading_font | font_face: font_display: 'swap' }}
{{ heading_font_heavy | font_face: font_display: 'swap' }}
{{ body_font | font_face: font_display: 'swap' }}
{{ body_font_bold | font_face: font_display: 'swap' }}
{{ body_font_italic | font_face: font_display: 'swap' }}
:root {
--lantern-font-heading: {{ heading_font.family }}, {{ heading_font.fallback_families }};
--lantern-font-heading-weight: {{ heading_font.weight }};
--lantern-font-body: {{ body_font.family }}, {{ body_font.fallback_families }};
--lantern-heading-scale: {{ settings.heading_scale | divided_by: 100.0 }};
...the colours from part 1...
}
{% endstyle %}
Four filters do the work. font_face writes the @font-face rule for one font, one weight, one style; it has to be inside a stylesheet, which {% style %} is. font_modify derives a variant of the same family, so the body gets its bold and italic faces and the headings get one step heavier than the merchant chose. font_url is the CDN URL of the file, which preload_tag turns into a <link rel="preload">. And system? is true when the merchant picked a system font, which has no files: font_url returns an empty string for it, so every tag that would request a file is guarded, while font_face returns nothing for a system font and needs no guard.
The Tailwind side reads the variables as before, plus one rule that makes the Heading size slider work on every heading at once:
h1, h2, h3, h4 { font-family: var(--font-heading); font-weight: var(--lantern-font-heading-weight, 700); letter-spacing: -0.02em; }
h1, h2 { font-size: calc(1em * var(--lantern-heading-scale, 1)); }
What the browser ends up with, read from the rendered page with document.fonts:
preloads: manrope_n7.f3a06f96….woff2, inter_n4.b2a3f24c….woff2
loaded: Manrope 700, Manrope 800, Inter 400, Inter 700
h1: Manrope, sans-serif, weight 800
Two preloads, five faces, and the hero's font-extrabold really is Manrope 800 rather than the browser thickening 700.
A section with blocks
"Shop by collection" is a grid of four tiles. The merchant should choose the collections and their order, and be able to override a tile's picture or title. That is what blocks are for: repeatable, reorderable units inside a section, each with its own settings.
<ul class="grid grid-cols-2 gap-5 {% if section.settings.columns == '3' %}md:grid-cols-3{% else %}md:grid-cols-4{% endif %}" role="list">
{%- for block in section.blocks -%}
{%- liquid
assign collection = block.settings.collection
assign title = block.settings.title | default: collection.title
assign image = block.settings.image | default: collection.image | default: collection.products.first.featured_image
-%}
<li {{ block.shopify_attributes }}>
<a href="{{ collection.url | default: '#' }}" class="group block rounded-tile overflow-hidden bg-ground-2 aspect-square relative">
{%- if image -%}
{{ image | image_url: width: 700 | image_tag: class: 'w-full h-full object-cover transition-transform duration-500 group-hover:scale-[1.03]', widths: '350, 500, 700', sizes: '(min-width: 768px) 25vw, 50vw', loading: 'lazy', alt: title }}
{%- else -%}
{{ 'collection-' | append: forloop.index | placeholder_svg_tag: 'w-full h-full object-cover opacity-60' }}
{%- endif -%}
<span class="absolute inset-x-0 bottom-0 p-5 pt-12 bg-gradient-to-t from-ink/60 to-transparent font-heading font-bold text-xl text-white">{{ title | default: 'Collection' }}</span>
</a>
</li>
{%- endfor -%}
</ul>
{% schema %}
{
"name": "Collection list",
"settings": [
{ "type": "text", "id": "heading", "label": "Heading", "default": "Shop by collection" },
{ "type": "select", "id": "columns", "label": "Columns on desktop", "options": [{ "value": "3", "label": "3" }, { "value": "4", "label": "4" }], "default": "4" },
{ "type": "checkbox", "id": "show_all", "label": "Show \"All collections\" link", "default": true }
],
"max_blocks": 8,
"blocks": [
{
"type": "collection",
"name": "Collection",
"settings": [
{ "type": "collection", "id": "collection", "label": "Collection" },
{ "type": "text", "id": "title", "label": "Title override", "info": "Leave empty to use the collection's title." },
{ "type": "image_picker", "id": "image", "label": "Image override", "info": "Falls back to the collection image, then its first product." }
]
}
],
"presets": [
{ "name": "Collection list", "blocks": [{ "type": "collection" }, { "type": "collection" }, { "type": "collection" }, { "type": "collection" }] }
]
}
{% endschema %}
Four things to notice. section.blocks is the merchant's list, in the merchant's order; the theme never decides how many tiles there are. block.shopify_attributes on each tile's element is what lets the editor outline a block in the preview and open its settings when the merchant clicks it; leave it out and the block exists but cannot be selected from the page. The collection setting hands Liquid the collection object, so collection.title, collection.url and collection.products.first all work without a lookup. And a chain of default filters is how a tile finds a picture: the merchant's override, else the collection's own image, else its first product's. This store's collections have no images, so every tile on the home page is a product photo.
The preset is what the merchant gets from Add section: a section with four empty collection blocks, each showing a placeholder from placeholder_svg_tag until a collection is picked. max_blocks stops the grid at eight.
Blocks declared this way, inside a section's schema, are called section blocks. They exist only in this section; another section wanting a collection tile would have to declare its own. For words, buttons and anything reused across sections, there is a second kind.
Theme blocks
Theme blocks live in a blocks/ directory at the theme root, one file per block, each with its own {% schema %}. Any section can accept them with a single line in its schema, and the same block then works in all of those sections. The theme has three:
{%- comment -%} blocks/heading.liquid {%- endcomment -%}
{%- liquid
case block.settings.size
when 'eyebrow'
assign tag = 'p'
assign class = 'eyebrow'
when 'lg'
assign tag = 'h2'
assign class = 'text-[30px] font-bold leading-tight'
when 'xl'
assign tag = 'h2'
assign class = 'text-[38px] font-bold leading-[1.1]'
else
assign tag = 'h3'
assign class = 'text-2xl font-bold leading-tight'
endcase
-%}
<{{ tag }} class="{{ class }}" {{ block.shopify_attributes }}>{{ block.settings.text }}</{{ tag }}>
{% schema %}
{
"name": "Heading",
"tag": null,
"settings": [
{ "type": "inline_richtext", "id": "text", "label": "Heading", "default": "Eleven workshops, one standard." },
{ "type": "select", "id": "size", "label": "Size", "options": [
{ "value": "eyebrow", "label": "Eyebrow" }, { "value": "md", "label": "Medium" }, { "value": "lg", "label": "Large" }, { "value": "xl", "label": "Extra large" }
], "default": "lg" }
],
"presets": [{ "name": "Heading" }]
}
{% endschema %}
blocks/text.liquid is a richtext setting in a <div>, and blocks/button.liquid is a text label, a url link and a select for solid or outline. "tag": null tells Shopify not to wrap the block in a <div> of its own, so the heading is a bare <h2> inside whatever the section puts around it. The inline_richtext value is HTML, bold and links included, so it is output without escape; the trade is that a merchant can only put in what the editor's small toolbar allows.
A section that accepts theme blocks does two things: declares @theme in its blocks list, and renders them with content_for 'blocks' where they should appear.
<section class="{{ band }}">
<div class="wrap grid gap-10 md:grid-cols-2 items-center py-16 md:py-[72px]">
<div class="rounded-tile overflow-hidden bg-ground-2 min-h-[320px] md:min-h-[420px] {% if section.settings.layout == 'text_first' %}md:order-2{% endif %}">
{{ section.settings.image | image_url: width: 1200 | image_tag: class: 'w-full h-full object-cover', widths: '600, 900, 1200', sizes: '(min-width: 768px) 50vw, 100vw', loading: 'lazy' }}
</div>
<div class="flex flex-col gap-4">
{% content_for 'blocks' %}
</div>
</div>
</section>
{% schema %}
{
"name": "Image with text",
"settings": [
{ "type": "image_picker", "id": "image", "label": "Image" },
{ "type": "select", "id": "layout", "label": "Image position", "options": [{ "value": "image_first", "label": "Image left" }, { "value": "text_first", "label": "Image right" }], "default": "image_first" },
{ "type": "select", "id": "background", "label": "Background", "options": [{ "value": "plain", "label": "Plain" }, { "value": "raised", "label": "Raised" }, { "value": "accent", "label": "Accent" }], "default": "raised" }
],
"blocks": [{ "type": "@theme" }, { "type": "@app" }],
"presets": [
{
"name": "Image with text",
"blocks": [
{ "type": "heading", "settings": { "text": "Made slowly", "size": "eyebrow" } },
{ "type": "heading", "settings": { "text": "Eleven workshops, one standard.", "size": "xl" } },
{ "type": "text" },
{ "type": "button" }
]
}
]
}
{% endschema %}
@theme means every block in blocks/; @app means blocks from installed apps, reviews and the like, which is what makes a section app-ready without the theme knowing which apps exist. The section owns the layout, the image and the background; the words are whatever blocks the merchant stacks in the right column, in the order they stack them. The preset gives them a reasonable start: eyebrow, big heading, paragraph, outline button.
sections/rich-text.liquid is twelve lines: a centred or left-aligned column with content_for 'blocks' and the same @theme line. Nothing was written twice. The rule that comes with this is that a section uses section blocks or theme blocks, not both, and theme blocks can nest eight levels deep if a block's own schema accepts @theme, which these do not need.
Featured collection, and the newsletter
Two more sections finish the page. Featured collection takes a collection picker and a range for how many to show, and reuses the card from part 2:
{%- liquid
assign collection = section.settings.collection
assign limit = section.settings.products_to_show
-%}
<ul class="grid grid-cols-2 md:grid-cols-4 gap-6" role="list">
{%- for product in collection.products limit: limit -%}
<li>{% render 'product-card', product: product %}</li>
{%- else -%}
{%- for i in (1..limit) -%}
<li><div class="aspect-card rounded-[14px] overflow-hidden bg-ground-2">{{ 'product-' | append: i | placeholder_svg_tag: 'w-full h-full object-cover opacity-60' }}</div></li>
{%- endfor -%}
{%- endfor -%}
</ul>
for ... else runs the else branch when the loop had nothing to iterate, which is the state right after Add section, before a collection is chosen. The range is min: 4, max: 12, step: 4, so the grid is always full rows.
The newsletter is the one section with a form, and it needs no app:
{%- form 'customer', class: 'flex flex-col gap-3 mt-1.5', id: 'NewsletterForm' -%}
{%- if form.posted_successfully? -%}
<p class="font-semibold text-accent" role="status">{{ 'sections.newsletter.success' | t }}</p>
{%- else -%}
<input type="hidden" name="contact[tags]" value="newsletter">
<div class="flex flex-wrap gap-2.5">
<label for="NewsletterEmail" class="sr-only">{{ 'sections.newsletter.email' | t }}</label>
<input id="NewsletterEmail" type="email" name="contact[email]" required autocomplete="email" placeholder="{{ 'sections.newsletter.placeholder' | t }}" class="flex-1 basis-[260px] min-h-12 px-4 rounded-full border border-line bg-white">
<button type="submit" class="btn">{{ section.settings.button_label | escape }}</button>
</div>
{%- if form.errors -%}
<p class="text-sm text-[#B42318]">{{ form.errors.translated_fields.email | capitalize }} {{ form.errors.messages.email }}</p>
{%- endif -%}
{%- endif -%}
{%- endform -%}
{% form 'customer' %} posts to Shopify's customer endpoint, which creates a customer with marketing consent and the tag in contact[tags], then re-renders the page with the form object filled: posted_successfully? on success, errors with translated field names and messages otherwise. The merchant sees the subscriber under Customers with the newsletter tag, which is what every email app reads from.
The home page as JSON
A JSON template lists sections, their settings and their blocks. The whole home page is the one file, abridged:
{
"sections": {
"hero": {
"type": "hero",
"settings": {
"heading": "Light your evenings slowly.",
"image": "shopify://shop_images/brass-hurricane-lantern-03-lifestyle.jpg",
"button_label": "Shop new arrivals",
"button_link": "shopify://collections/new-arrivals"
}
},
"collection_list": {
"type": "collection-list",
"blocks": {
"bedding": { "type": "collection", "settings": { "collection": "bedding" } },
"lighting": { "type": "collection", "settings": { "collection": "lighting" } },
"tableware": { "type": "collection", "settings": { "collection": "tableware" } },
"decor": { "type": "collection", "settings": { "collection": "decor" } }
},
"block_order": ["bedding", "lighting", "tableware", "decor"],
"settings": { "heading": "Shop by collection", "columns": "4", "show_all": true }
},
"featured": { "type": "featured-collection", "settings": { "collection": "best-sellers", "products_to_show": 4 } },
"makers": {
"type": "image-with-text",
"blocks": {
"eyebrow": { "type": "heading", "settings": { "text": "Made slowly", "size": "eyebrow" } },
"heading": { "type": "heading", "settings": { "text": "Eleven workshops, one standard.", "size": "xl" } },
"text": { "type": "text" },
"button": { "type": "button", "settings": { "label": "Meet the makers", "link": "shopify://collections/handcrafted" } }
},
"block_order": ["eyebrow", "heading", "text", "button"],
"settings": { "image": "shopify://shop_images/brass-table-lamp-03-lifestyle.jpg", "background": "raised" }
},
"newsletter": { "type": "newsletter", "settings": {} }
},
"order": ["hero", "collection_list", "featured", "makers", "newsletter"]
}
In a JSON file a collection is its handle and an image is a shopify://shop_images/ URL pointing at the store's Files, where every product photo from part 1's import already is; Liquid turns both into objects when the page renders. The ids (hero, makers, bedding) are the theme's choice and become part of the section's DOM id. When the merchant edits the page, the editor writes this same file back, which is why a shopify theme pull after a merchant has been busy brings down a changed templates/index.json, and why a theme developer's own template commits can clash with it.
In the editor
The push prints the editor link; the sections sidebar shows what the JSON described, with the two block-bearing sections expandable. Click a block in the sidebar or in the preview:

The outline in the preview is block.shopify_attributes at work, and the panel on the right is the block's schema rendered: an inline_richtext field with its small toolbar and a select. Add block lists the three theme blocks, with an Apps tab for app blocks since the section accepts @app:

And Theme settings has the Typography group, with the header and paragraph entries rendered as a title and help text above the two font pickers and the range:

Change the heading font there and every h1 to h4 follows, because they all read one CSS variable. Nothing was saved in this session; the Save button stayed grey, and the theme on the store is exactly the repository.
shopify theme check
48 files inspected with no offenses found.
What went wrong
"tag": null is for blocks, not sections. I put it on every new section too, to avoid the wrapper <div>, and Theme Check refused each one with Value is not accepted. Valid values: "article", "aside", "div", "footer", "header", "section". A section always gets a wrapper with the shopify-section- id; the choice is only which element. The line stays on the three blocks, where it is valid, and came off the five sections.
The hero's 800 weight was fake. The font picker loads exactly the weight the merchant chose, 700, and the hero's font-extrabold asked for 800, so the browser synthesised it: thicker strokes, worse shapes. document.fonts listed only Manrope 700. One font_modify: 'weight', '+100' and a second font_face later, Manrope 800 is on the list and the hero uses the real face.
The collections were invisible. Part 2 ended with the store needing collections; they were created with automated conditions, and the storefront still listed one. Sixteen of seventeen had been created without the Online Store sales channel, which a theme cannot do anything about: collections.json and /collections showed one until each was published to the channel, through the Admin API's publishablePublish mutation, after which both showed seventeen. A collection the storefront cannot see is the first thing to check when collections['handle'] comes back empty in Liquid.
No collection has an image, so the tiles fell back to each collection's first product, which is the chain of default filters above. That was always the intended fallback; what changed is that it turned out to be the only branch running.
Part 4 is the JavaScript the theme has been postponing: a variant picker that updates the price, button and gallery without a page load, the Ajax cart API, and the cart drawer that opens when a product is added.
New posts by email
Get new posts by email. Nothing else, no digests, unsubscribe in one click.
Comments
Comments are GitHub Discussions in shipbytes/discussions. Sign in with GitHub to post.
In this series
3 / 6- OverviewBuild a Shopify theme from scratch, with Liquid
- Part 1The anatomy of a theme, and one that renders
- Part 2Liquid on the product and collection pages
- Part 3Sections, blocks and the theme editor
- Part 4Variants without reloads, the Cart API and a cart drawer
- Part 5Search, pagination, metafields, translations and customers
- Part 6Performance, accessibility, Theme Check and publishing