Skip to content
Hekana Spray
Documentation
Getting started
Theme development
Components and tags

Localization

Apps and custom code

Examples and recipes
API reference
Publishing
Build apps
AI development

Sections and blocks

Define sections and blocks with <hk-schema>: field types, how settings are coerced, template default sections and repeatable blocks.

On this page

A section is a page part a merchant adds, removes, reorders and configures: a hero, a product grid, testimonials. A block is an item inside a section that the merchant can add several of: one testimonial, one slide. Both are a template plus a <hk-schema> that declares their settings.

A section

A hero: a dark band with a big heading, a sentence and a button. This is the smallest useful section.

sections/hero.snfSneferu
<hk-section background="theme:secondary" padding-y="96" mobile-padding-y="48">
  <hk-stack gap="16" align="start">
    <hk-heading text="{{ section.settings.title }}" level="h1" size="56" mobile-size="32" color="#FFFFFF" />
    <hk-text text="{{ section.settings.subtitle }}" size="20" color="#E5E7EB" />
    <hk-button label="{{ t('shop_now') }}" href="/products" />
  </hk-stack>
</hk-section>
<hk-schema>
  {
    "name": "Hero",
    "version": 1,
    "settings": {
      "title": {
        "type": "text",
        "label": "Title",
        "default": "Hello",
        "maxLength": 80
      },
      "subtitle": {
        "type": "textarea",
        "label": "Subtitle",
        "default": "",
        "maxLength": 200
      }
    }
  }
</hk-schema>
Result
This hero in the dev preview, 1080 px wide.

What each line does

  1. Line 1 <hk-section> is the band. background="theme:secondary" paints it with the theme's secondary colour from theme.json. padding-y="96" is the space above and below the content; mobile-padding-y="48" halves it on phones.
  2. Line 2 <hk-stack> puts the heading, sentence and button in a column, 16 px apart, lined up at the start of the line.
  3. Line 3 <hk-heading> is the title. {{ section.settings.title }} prints the title setting: what the merchant typed, or the default.
  4. Line 4 <hk-text> prints the subtitle setting.
  5. Line 5 <hk-button> is a link drawn as a button. t('shop_now') takes its words from locales/en.json.
  6. Lines 8-27 <hk-schema> declares the settings the merchant edits in the store builder.

Rules for the file:

  • The file name is the section type: hero.
  • <hk-schema> is JSON (double quotes, no trailing commas; SN1107). Put it at the end of the file.
  • name is required (SN3030). It is what merchants see in the builder.
  • version is the schema version (a number, default 1).
  • settings is an object of fields. Read them as section.settings.<key>.
  • Inside a section you also have section.id, section.type and section.blocks.

Field types

Every field is:

json
{ "type": "…", "label": "…", "default": …, "min": …, "max": …, "step": …,
  "options": […], "maxLength": …, "required": …, "responsive": …, "visible_if": { "setting": "…", "equals": … } }

Only type and label are needed. One example of each type:

TypeValue in templatesExample field
textshort string"title": { "type": "text", "label": "Title", "default": "Summer sale", "maxLength": 80 }
textarealonger string"body": { "type": "textarea", "label": "Body", "default": "" }
rich_textstring"story": { "type": "rich_text", "label": "Story", "default": "" }
numbernumber"padding": { "type": "number", "label": "Padding", "default": 64, "min": 0, "max": 240 }
rangenumber (slider)"count": { "type": "range", "label": "Count", "default": 8, "min": 2, "max": 24, "step": 1 }
booleantrue / false"show_title": { "type": "boolean", "label": "Show title", "default": true }
selectone of options"align": { "type": "select", "label": "Align", "options": ["start", "center", "end"], "default": "start" }
color#hex or theme:<token>"background": { "type": "color", "label": "Background", "default": "theme:background" }
imageimage reference (URL string)"image": { "type": "image", "label": "Image" }
videovideo reference"video": { "type": "video", "label": "Video" }
linkURL string"link": { "type": "link", "label": "Link", "default": "/products" }
iconicon name"icon": { "type": "icon", "label": "Icon", "default": "truck" }
productproduct handle"product": { "type": "product", "label": "Product" }
collectioncollection handle"collection": { "type": "collection", "label": "Collection", "default": "featured" }
menumenu handle"menu": { "type": "menu", "label": "Menu", "default": "main" }: read it with menu(section.settings.menu) (see Menus)
spacingstring"gap": { "type": "spacing", "label": "Spacing", "default": "md" }
typographystring"font": { "type": "typography", "label": "Typography", "default": "body" }

Notes:

  • product and collection store a handle string. product() and collection() take a literal handle or a setting of their own type: collection(section.settings.collection) reads the collection the merchant picked. Any other argument is SN1105 (see Data and expressions).
  • required, visible_if (show this field only when another setting equals a value) and responsive are hints for the editor. Rendering does not enforce required; always set a sensible default.
  • Labels are shown to merchants in the dashboard: keep them short and plain.

How settings reach the page (coercion)

The merchant's stored values are never trusted as-is. Before a section renders, each declared setting is filled and coerced:

SituationResult
No stored valuedefault (or nothing, if there is no default)
text, textarea, rich_text, image, video, link, icon, product, collection, menu, spacing, typographymust be a string, else default; cut to maxLength if set
number, rangenumbers and numeric strings are parsed and clamped to min/max; anything else gives default
booleantrue, "true", "yes", 1 → true; false, "false", "no", 0 → false; else default
selectmust be one of options, else default
colormust be # + 3-8 hex digits or theme:<token>, else default
Setting not declared in the schemadropped; templates never see it

So a stored padding of "999" with max: 240 renders as 240, and an align of "diagonal" renders as the default "start". A bad value never breaks the page.

Values written directly on hk-* tags are not coerced by your schema; each tag checks its own props (a size outside its range is clamped, an unknown variant falls back to the tag default). See the tag reference.

Template default sections

A template's <hk-schema> lists the sections a new page starts with, in order:

html
<hk-sections />
<hk-schema>{"sections":[
  {"type":"hero","settings":{"title":"Welcome","subtitle":"A theme built with Sneferu"}},
  {"type":"featured","settings":{"title":"Featured products"}}
]}</hk-schema>
  • type must be a file in sections/ (SN3020); each entry is { "type", "settings"? } (SN3026).
  • settings here go through the same coercion as stored values.
  • A default section may also list blocks (see below). They are what sneferu dev shows.
  • Once a merchant edits the page, their saved list of sections replaces the defaults.

Default blocks

A default section can start with blocks. Each entry is { "type", "settings"? }:

html
<hk-sections />
<hk-schema>{"sections":[
  {"type":"faq","settings":{"title":"Questions"},"blocks":[
    {"type":"question","settings":{"text":"How long does shipping take?"}},
    {"type":"question","settings":{"text":"Can I return an item?"}}
  ]}
]}</hk-schema>
  • Each type must be a file in blocks/ (SN3028).
  • The section must allow the type in blocks.allowed, and the list may not be longer than blocks.max (SN3029).
  • The blocks render with the ids default-<section index>-<block index>, for example default-0-1.

Text in two languages

Add "localized": true to a text, textarea or rich_text setting and the merchant can store one value per language:

json
"title": {
  "type": "text",
  "label": "Title",
  "localized": true,
  "default": { "ar": "أهلًا بك", "en": "Welcome" }
}

Templates still read {{ section.settings.title }} and get a plain string: the value for the page's language, else the other language, else the default, else an empty string. A plain string saved by an older editor is used as it is in both languages. maxLength applies to the resolved string. Theme-level settings in theme.json can be localized the same way.

Blocks

A customer quotes section: the merchant adds as many quotes as they like, up to six, and edits each one. Each quote is a block.

blocks/quote.snfSneferu
<hk-card border="true" padding="20" radius="16">
  <hk-stack gap="10">
    <p class="quote">{{ block.settings.text }}</p>
    <hk-text text="{{ block.settings.author }}" size="14" color="#4B5563" />
  </hk-stack>
</hk-card>
<hk-schema>
  {
    "name": "Quote",
    "version": 1,
    "settings": {
      "text": {
        "type": "textarea",
        "label": "Quote",
        "default": "Delivery was fast and the packaging was perfect.",
        "maxLength": 280
      },
      "author": {
        "type": "text",
        "label": "Name",
        "default": "Mona, Alexandria",
        "maxLength": 60
      }
    }
  }
</hk-schema>
sections/testimonials.snfSneferu
<hk-section padding-y="64" mobile-padding-y="40">
  <hk-stack gap="24">
    <hk-heading text="{{ section.settings.heading }}" level="h2" size="32" mobile-size="24" />
    {% if section.blocks %}
      <hk-grid columns="3" mobile-columns="1" gap="16">
        {% for block in section.blocks %}
          <hk-block of="{{ block }}" />
        {% endfor %}
      </hk-grid>
    {% else %}
      <hk-text text="{{ t('no_quotes_yet') }}" color="#4B5563" />
    {% endif %}
  </hk-stack>
</hk-section>
<hk-schema>
  {
    "name": "Testimonials",
    "version": 1,
    "settings": {
      "heading": {
        "type": "text",
        "label": "Heading",
        "default": "What our customers say"
      }
    },
    "blocks": {
      "allowed": ["quote"],
      "max": 6
    },
    "presets": [
      {
        "name": "Three quotes",
        "blocks": [
          {
            "type": "quote"
          },
          {
            "type": "quote"
          },
          {
            "type": "quote"
          }
        ]
      }
    ]
  }
</hk-schema>
assets/quote.csscss
.quote { margin: 0; font-size: 17px; line-height: 1.6; }
Result
With three quote blocks, 1080 px wide. Rendered by the Sneferu runtime with three blocks passed in.

What each line does

In blocks/quote.snf:

  1. Lines 1-6 one quote: a bordered card with the quote and the customer's name. A block reads its own settings as block.settings.<key>.
  2. Lines 7-26 the two settings of one quote: the text and the name.

In sections/testimonials.snf:

  1. Line 4 {% if section.blocks %} is true when the merchant has added at least one quote.
  2. Lines 6-8 {% for block in section.blocks %} goes through the quotes in the merchant's order, and <hk-block of="{{ block }}" /> draws each one with blocks/quote.snf.
  3. Lines 10-11 what shows when there are no quotes yet.
  4. Lines 26-29 "blocks" tells the builder which block types this section takes (quote) and how many (6 at most).
  5. Lines 30-45 "presets": when the merchant adds this section, the builder offers to start it with three quotes.

How it works:

  • section.blocks is the list of the merchant's blocks in order, hidden ones removed. Each has id, type and coerced settings.
  • <hk-block of="{{ block }}" /> renders blocks/<type>.snf with block in scope, wrapped in <div data-hk-block="<id>">. The section's scope (section, store, …) stays visible.
  • A block whose type is not in the theme is skipped with SN4012; the rest of the section renders.
  • blocks.allowed (which block types the editor offers) and blocks.max are read by the editor. The platform also caps a section at 50 blocks and a page at 60 sections.
  • presets are starting configurations the editor offers when the section is added. They are stored with the theme and used by the builder; the CLI does not render them.
  • Because default sections cannot carry blocks, sneferu dev shows a block section with no blocks. Design that state, as lines 10-11 do: it is also what a merchant sees right after adding the section.

Try it

  1. Save the three files and add the key to locales/en.json: "no_quotes_yet": "No quotes yet. Add one in the editor.".
  2. Add {"type":"testimonials"} to templates/index.snf.
  3. Run npx sneferu validate and look at the preview: you see the empty state.

Snippets vs blocks

UseWhen
BlockThe merchant decides how many there are and edits each one
Snippet ({% render %})You repeat markup in code, with values you pass in

{% render 'price-tag', amount: p.price %} renders snippets/price-tag.snf with amount in scope, on top of the caller's scope. Snippets nest up to 8 deep and may not render each other in a cycle (SN3027).

Next steps