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

Tutorial: build a digital products store theme

Tutorial: build a Sneferu theme for a digital products store, from a design mockup to a live Hekana store, with the Bento example theme.

On this page

This tutorial builds Bento, a home page for a shop that sells printables, templates and e-books as digital files, from a design mockup to a live store. It uses only the CLI and the parts of Sneferu described in the earlier chapters. The finished theme is live at demo-bento.hekana.com (Arabic) and demo-bento.hekana.com/en (English).

This page shows the key part of each file. Full theme on GitHub: examples/themes/bento, with its own README.md. Every excerpt links to its whole file. To run it yourself:

bash
git clone --depth 1 https://github.com/hekanahq/sneferu
cd sneferu/examples/themes/bento
npx sneferu dev

The mockup was generated as a design brief. Its Arabic is placeholder text, and its lavender and pink tiles become sky blue and peach.

The home page template lists the sections and seeds their repeated items (tabs, shelves, list items, questions) as blocks, so a fresh install shows the whole page. The excerpt shows the first section and its first block.

examples/themes/bento/templates/index.snf (excerpt)Sneferu
<hk-sections />
<hk-schema>
  {
    "sections": [
      {
        "type": "tabs",
        "blocks": [
          {
            "type": "tab",
            "settings": {
              "label": {
                "ar": "الكل",
                "en": "All"
              },
              "link": "#shop",
              "current": true
            }
          },

View full file on GitHub

Result
A pastel mockup: category tabs, two coloured header tiles, two panels with three illustrated covers each, and a teal band
The mockup the theme reproduces.

Two more themes were built the same way and follow the same steps. Each home page is a template listing its sections, like Bento's above:

ThemeWhat it showsLiveFiles
Creatoreditorial covers in a scroll-snap row, a checklist, an author stripdemo-creator.hekana.comexamples/themes/creator
Licensedark, plan cards built from products, app cards, a FAQ accordiondemo-license.hekana.comexamples/themes/license
examples/themes/creator/templates/index.snf (excerpt)Sneferu
<hk-sections />
<hk-schema>
  {
    "sections": [
      {
        "type": "covers"
      },
      {
        "type": "what-you-get",
        "blocks": [
          {
            "type": "get-item",
            "settings": {
              "term": {
                "ar": "الملفات",
                "en": "Files"
              },
              "text": {
                "ar": "رابط التحميل بيوصلك على الإيميل بعد الدفع أونلاين",
                "en": "Your download link is emailed after online payment"
              }
            }
          },

View full file on GitHub

examples/themes/license/templates/index.snf (excerpt)Sneferu
<hk-sections />
<hk-schema>
  {
    "sections": [
      {
        "type": "plans-hero"
      },
      {
        "type": "features",
        "blocks": [
          {
            "type": "feature",
            "settings": {
              "text": {
                "ar": "مفتاح الترخيص على الإيميل بعد الدفع",
                "en": "Licence key by email after payment"
              }
            }
          },

View full file on GitHub

Result
Creator: two large dark covers with orange badges, a checklist and an author strip on warm paper
Creator, examples/themes/creator/.

Each example folder has a README.md that walks through its own files the same way this page walks through Bento.

1. Plan the data

Before writing a template, decide what the page reads. Bento shows two categories of products. Each shelf has a collection setting, so the merchant picks the category in the editor; the theme's defaults are these handles:

HandleShelf
printablesthe first shelf
templatesthe second shelf

A store that has categories with these handles shows the page filled in on install; any other store picks its own. Everything else on the page is a product field (title, url, price, image), a setting, or a word from the locale files.

2. Create the theme and the sample data

bash
npx sneferu init bento
cd bento

Delete the starter's sections/hero.snf, sections/featured.snf and blocks/chip.snf; the theme writes its own.

The dev preview's built-in sample products are game cards, and its only collection is featured. To preview with this store's own products, write .sneferu-dev/data.json. It can be split by locale, one block per language:

examples/themes/bento/.sneferu-dev/data.json (excerpt)JSON
 "en": {
  "store": {
   "name": "Daftar"
  },
  "collections": {
   "printables": {
    "title": "Printables",
    "products": [
     {
      "title": "Sunny colouring book",
      "url": "/en/products/sunny-colouring-book",
      "price": 6900,
      "compare_at": null,
      "image": {

View full file on GitHub

That is the start of the "en" block; an "ar" block before it has the same products with Arabic titles, so ?locale=ar previews in Arabic. The folder starts with a dot, so it is never part of the theme and never pushed. (Getting started has the details; it needs the CLI from Sneferu main after #16.)

3. Tokens

examples/themes/bento/theme.json (excerpt)JSON
  "defaultLocale": "ar",
  "locales": ["ar", "en"],
  "settings": {},
  "tokens": {
    "colors": {
      "primary": "#1F2433",
      "secondary": "#74B8AE",
      "accent": "#E9946C",
      "background": "#FFFFFF",
      "text": "#1F2433",
      "muted": "#5F6474",
      "sage": "#CFE3D7",
      "peach": "#F7C9AF",
      "warm": "#FCF1EA",
      "sky": "#E8F1FA",
      "teal": "#74B8AE",
      "line": "#E8E6E1"
    },
    "layout": { "contentWidth": "1040px" },
    "fonts": {
      "heading": "Baloo Bhaijaan 2",
      "body": "Baloo Bhaijaan 2"
    }

View full file on GitHub

  • defaultLocale: "ar" makes / Arabic, right to left; /en is English.
  • Every colour the page uses is a token. The extra keys (sage, peach, warm, sky, teal, line) become --hk-color-sage and so on.
  • No purple, lavender or pink anywhere: the mockup's lavender panel is sky and its pink tile is peach.

The font is a token: "fonts": { "heading": "Baloo Bhaijaan 2", "body": "Baloo Bhaijaan 2" }. Baloo Bhaijaan 2 is in the font catalogue and has Arabic glyphs; Hekana serves the files and sets the family on the theme root, so the stylesheet has no @font-face and no font-family:

examples/themes/bento/assets/theme.css (excerpt)css
.bt {
  background: var(--hk-color-background);
  color: var(--hk-color-text);
  line-height: 1.5;
  min-height: 100vh;
}

View full file on GitHub

4. Layout

examples/themes/bento/layout/theme.snfSneferu
<div class="bt">
  <hk-section-group name="header" />
  <main><hk-slot name="content" /></main>
  <hk-section-group name="footer" />
</div>

View full file on GitHub

The header and the footer are section groups: groups/header.json and groups/footer.json start them with the sections bento-header and bento-footer, and the merchant edits them once for the whole store. The end of the header row, with the cart, the search and the phone menu:

examples/themes/bento/sections/bento-header.snf (excerpt)Sneferu
    <div class="bt-end">
      <a
        class="bt-icon bt-hide-phone"
        href="{{ url('/cart') }}"
        data-hk-open="cart-drawer"
        aria-label="{{ t('cart') }}"
      ><hk-icon name="shopping-bag" /><hk-cart-count /></a>
      <a class="bt-icon bt-hide-phone" href="{{ url('/search') }}" aria-label="{{ t('search') }}"><hk-icon
          name="search"
        /></a>
      <a class="bt-pill" href="{{ url('/products') }}">{{ t('all_products') }}</a>
      <details class="bt-menu">
        <summary class="bt-icon" aria-label="{{ t('menu') }}"><hk-icon name="menu" size="22" /></summary>
        <div class="bt-menu-panel">
          {% for item in menu(section.settings.menu).items %}<a
              href="{{ item.url }}"
              aria-current="{{ item.active }}"
            >{{ item.title }}</a>{% endfor %}<a href="{{ url('/search') }}">{{ t('search') }}</a>
          <a href="{{ url('/cart') }}" data-hk-open="cart-drawer">{{ t('cart') }}</a>
          <a href="{{ url('/wishlist') }}">{{ t('wishlist') }}</a>
          <hk-locale-switch />
        </div>
      </details>

View full file on GitHub

  • The page goes where <hk-slot name="content" /> is.
  • Cart links carry data-hk-open="cart-drawer": with the controllers running they open <hk-cart-drawer>, without them they go to the cart page. <hk-cart-count /> shows the number of items.
  • All words are t('…'). Links go through url(): url('/cart') is /cart on an Arabic page and /en/cart on an English one. The language switch is <hk-locale-switch />: it links to the same page in the other language.
  • The phone menu is <details>/<summary>: it opens without script.
  • The menu panel starts with the store's own menu, menu(section.settings.menu) (the main menu unless the merchant picks another); see Menus.
  • Icons are <hk-icon name="shopping-bag" /> from the bundled set. The filled avatar has no match in the set, so it stays an inline SVG in snippets/glyph.snf.

5. The template

The template is the one shown at the top of this page: three sections, in order, with their default blocks: four tabs and two shelves. A merchant can reorder the sections, edit or add blocks, or add more sections in the builder.

6. The shelves

This is the heart of the page: a section whose blocks are shelves. Each shelf block has its own collection, words and colours.

examples/themes/bento/sections/bento.snfSneferu
<section class="bt-bento" id="shop">
  <div class="bt-wrap bt-bento-grid">
    {% for block in section.blocks %}
      <hk-block of="{{ block }}" />
    {% endfor %}
  </div>
</section>
<hk-schema>
  {
    "name": "Bento shelves",
    "version": 1,
    "settings": {},
    "blocks": {
      "allowed": ["shelf"],
      "max": 4
    }
  }
</hk-schema>

View full file on GitHub

examples/themes/bento/blocks/shelf.snf (excerpt)Sneferu
<div class="bt-shelf" id="{{ block.settings.list }}">
  <a class="bt-head" data-tone="{{ block.settings.head }}" href="{{ url(block.settings.link) }}">
    <h2>{{ block.settings.title }}</h2>
    <span class="bt-thumbs" aria-hidden="true">
      {% for p in collection(block.settings.list).products limit: 5 %}
        {% if p.image %}<img src="{{ p.image.url }}" alt="" width="28" height="28" loading="lazy" />{% endif %}
      {% endfor %}
    </span>
  </a>
  <div class="bt-panel" data-tone="{{ block.settings.panel }}">
    <div class="bt-chips">
      <span class="bt-chip bt-chip-on">{{ t('chip_instant') }}</span>
      <span class="bt-chip">{{ t('chip_pdf') }}</span>
      <span class="bt-chip">{{ block.settings.note }}</span>
    </div>
    {% if collection(block.settings.list).products %}
      <div class="bt-covers">
        {% for p in collection(block.settings.list).products limit: block.settings.count %}
          <div class="bt-cover">
            <hk-product-card product="{{ p }}" class="bt-card">
              <hk-part name="badge">{% if forloop.first %}<span class="bt-new">{{ t('badge_new') }}</span>{% endif %}</hk-part>
            </hk-product-card>
          </div>
        {% endfor %}
      </div>

View full file on GitHub

Result
Two shelves side by side: a peach header tile over a sky-blue panel and a sage header tile over a sand panel, each with three covers
The shelves in English, 1040 px of content.

How it works

  1. collection(block.settings.list) reads the collection the merchant picked for this shelf (printables and templates in the template). With nothing picked it is empty, and nothing is fetched.
  2. data-tone="{{ block.settings.head }}" writes peach, sage, sky or warm. A template cannot build a style="…" from data (SN2009), so the colour comes from one CSS rule per tone: [data-tone="peach"] { background: var(--hk-color-peach); }.
  3. {% for p in collection(block.settings.list).products limit: 5 %} draws the round thumbnails in the header tile; the covers use limit: block.settings.count, a range setting.
  4. {% if collection(block.settings.list).products %} is false for an empty collection: the panel then shows one line of text instead of an empty grid.
  5. <hk-product-card product="{{ p }}" class="bt-card"> renders the cover, the title and the price as one link. The "New" badge is its badge part (<hk-part name="badge">), so it sits inside the link, before the image, and only on forloop.first.
  6. The shelf's id is the collection handle, so the tab links #printables and #templates scroll to the shelves.

The grid and the covers, from the stylesheet:

examples/themes/bento/assets/theme.css (excerpt)css
/* Bento shelves: a header tile over a panel, two side by side */
.bt-bento { padding-block: 0 24px; }
.bt-bento-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bt-shelf { display: flex; flex-direction: column; gap: 10px; }
.bt-head {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 18px 24px 16px;
  border-radius: 28px; min-height: 84px;
}
.bt-head h2 { margin: 0; font-size: 21px; font-weight: 600; line-height: 1.3; }
.bt-thumbs { display: flex; }
.bt-thumbs img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; border: 2px solid #FFFFFF; margin-inline-end: -6px; }
.bt-panel { position: relative; padding: 18px 22px 60px; border-radius: 28px; }
.bt-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.bt-chip { font-size: 12.5px; padding: 3px 12px; border-radius: 999px; color: var(--hk-color-muted); }
.bt-chip-on { background: var(--hk-color-peach); color: var(--hk-color-text); }
.bt-covers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.bt-cover { position: relative; }
.bt-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; }
.bt-card img { width: 100%; aspect-ratio: 5 / 6; object-fit: cover; border-radius: 16px; display: block; margin-bottom: 6px; }
.bt-card .sn-title { font-size: 13px; font-weight: 600; line-height: 1.35; }

View full file on GitHub

7. The band

examples/themes/bento/sections/band.snf (excerpt)Sneferu
<section class="bt-band-wrap">
  <div class="bt-wrap">
    <div class="bt-band">
      <div>
        <h2>{{ section.settings.heading }}</h2>
        <p>{{ section.settings.text }}</p>
      </div>
      <hk-button label="{{ section.settings.button }}" href="{{ section.settings.link }}" class="bt-band-button" />
    </div>
  </div>
</section>

View full file on GitHub

examples/themes/bento/sections/band.snf (excerpt)JSON
      "heading": {
        "type": "text",
        "label": "Heading",
        "localized": true,
        "default": {
          "ar": "اطبع النهارده",
          "en": "Print it today"
        },
        "maxLength": 80
      },

View full file on GitHub

Result
A teal band with a heading, one line of text and a dark pill button
The band in English.

The text settings are "localized": true, with a default in each language, like the heading above. The editor shows one field per language, and {{ section.settings.heading }} prints the one for the page. The button link is a link setting; hk-button keeps it in the page's language.

hk-button renders <a class="sn-btn sn-btn-solid"> with no visual style of its own; the theme styles it through the class it passes (bt-band-button).

8. Phones

One media query at 639 px, the width the mobile- props use, stacks the shelves and rearranges the header:

examples/themes/bento/assets/theme.css (excerpt)css
@media (max-width: 639px) {
  .bt-wrap { padding-inline: 12px; }
  .bt-hide-phone { display: none; }
  .bt-menu { display: block; }
  .bt-header-row { justify-content: flex-start; gap: 6px; }
  .bt-start, .bt-end { display: contents; }
  .bt-menu { order: -1; }
  .bt-logo { margin: 0; }
  .bt-pill { margin-inline: auto 0; min-height: 44px; padding-inline: 18px; font-size: 13px; }
  .bt-user { display: none; }
  .bt-tabs { padding-block: 4px 10px; }
  .bt-tabs-row { justify-content: flex-start; gap: 20px; }
  .bt-tabs-row a { font-size: 15px; }
  .bt-bento-grid { grid-template-columns: 1fr; gap: 10px; }
  .bt-head { border-radius: 24px; padding: 14px 20px; min-height: 76px; }
  .bt-head h2 { font-size: 19px; }
  .bt-panel { padding: 14px 12px 56px; border-radius: 24px; }
  .bt-covers { gap: 8px; }
  .bt-card .sn-title { font-size: 12px; }
  .bt-band { border-radius: 28px; padding: 22px; justify-content: center; text-align: center; }
  .bt-band-button.sn-btn { width: 100%; }
}

View full file on GitHub

9. Check, preview and push

  1. npx sneferu format indents every file.
  2. npx sneferu validate prints ✔ theme [email protected] is valid.
  3. npx sneferu dev and open http://127.0.0.1:4100, then ?locale=en. Narrow the window below 640 px.
  4. Change id in theme.json to a slug of your own, then npx sneferu push . --package <your-slug> --dev-store.
  5. On a real store, create the two categories with the handles from step 1, or pick other categories for the shelves in the editor.

Every page of the store goes through the theme: Bento 2.0 has its own product, collection, search, cart, content page and 404 templates, and a shared header, footer and announcement bar the merchant edits once (see Page types and Section groups).

What to know before you build your own

The three digital themes were first built on Sneferu 0.2; version 2.0 (Sneferu 0.6) made them complete stores. What is still missing:

LimitWhat the three themes do
no carousel and no JavaScriptmenus and questions use <details>; Creator's covers row is scroll-snap with anchor dots
images in assets/ are served, but these themes bundle noneart comes from products, inline SVG, or an image setting with an https:// default
url() cannot link to the other language<hk-locale-switch /> links to the same page in the other language (since Sneferu 0.4)
money prints two decimals unless the theme sets "money": { "format": "whole" }these themes keep two decimals (EGP 69.00)

Next steps