Cookbook
Five complete Sneferu store sections, each with a picture of the result: an announcement bar, a hero, a feature row, a product grid and plans.
On this page
Five store sections you can copy into a theme as they are: an announcement bar,
a hero, a feature row, a product grid and subscription plans. Each one shows the
file, explains it line by line, and shows a picture of what it renders. Every
picture on this page is a screenshot of the section rendered by the Sneferu
runtime with the sneferu dev sample data, not a drawing.
The complete theme, with all five sections, is in the SDK repository under
docs/examples/example-store/. It passes validate with no errors and no
warnings. The last section shows the five together.
Before you start
Create a theme and keep the preview open while you work:
npx sneferu init my-store
npx sneferu dev ./my-storeOpen http://127.0.0.1:4100. It reloads every time you save a file.
The starter's assets/theme.css already styles buttons, badges and product
cards. Add one more file next to it:
h1, h2, h3, h4, p { margin: 0; }- Line 1 removes the browser's default space above and below headings and
paragraphs, so the spacing you set with
gaponhk-stackis the only spacing between them.
Then list the sections on the home page, in the order you want them. Replace
the content of templates/index.snf with:
<hk-sections />
<hk-schema>
{
"sections": [
{
"type": "announcement-bar"
},
{
"type": "promo-hero"
},
{
"type": "feature-row"
},
{
"type": "product-grid"
},
{
"type": "pricing"
}
]
}
</hk-schema>- Line 1
<hk-sections />is where the page's sections go. - Lines 2-20 list the sections a new home page starts with. Each
typeis a file name insections/without.snf. Add them one by one as you build each section below; a type with no file yet is an error (SN3020).
Announcement bar
A thin coloured strip at the top of the page with one message and a link, for news such as free delivery or a sale.
<hk-section background="{{ section.settings.background }}" padding-y="12" class="announcement">
<hk-stack direction="row" mobile-direction="column" gap="12" mobile-gap="4" align="center" justify="center">
<hk-text text="{{ section.settings.message }}" size="15" align="center" color="#FFFFFF" />
{% if section.settings.link_label %}
<a class="announcement-link" href="{{ section.settings.link }}">{{ section.settings.link_label }}</a>
{% endif %}
</hk-stack>
</hk-section>
<hk-schema>
{
"name": "Announcement bar",
"version": 1,
"settings": {
"message": {
"type": "text",
"label": "Message",
"default": "Free delivery on orders over EGP 500",
"maxLength": 90
},
"link_label": {
"type": "text",
"label": "Link text",
"default": "See details",
"maxLength": 30
},
"link": {
"type": "link",
"label": "Link",
"default": "/pages/delivery"
},
"background": {
"type": "color",
"label": "Background",
"default": "theme:accent"
}
}
}
</hk-schema>.announcement-link { color: #FFFFFF; font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
display: inline-flex; align-items: center; min-height: 44px; }What each line does
- Line 1
<hk-section>is the strip. Itsbackgroundcomes from thebackgroundsetting (lines 31-35), which starts as the theme's accent colour.padding-y="12"keeps it thin.class="announcement"is a name you can use in your CSS. - Line 2
<hk-stack>lays out the message and the link in one row, centred, 12 px apart. On phones (mobile-direction="column") they stack. - Line 3
<hk-text>prints the message the merchant typed, in white. - Lines 4-6
{% if section.settings.link_label %}shows the link only when the merchant filled in the link text. The link is a plain HTML<a>; you can mix plain HTML withhk-*tags. - Lines 9-38
<hk-schema>declares what the merchant can edit in the store builder: the message, the link text, the link and the colour. Each setting has a type, a label and a default. - In the CSS file,
.announcement-linkmakes the link white, bold and underlined, and at least 44 px tall so it is easy to tap.
Try it
- Save both files.
- Add
{"type":"announcement-bar"}totemplates/index.snf. - Run
npx sneferu validate ./my-store. It should print✔ theme [email protected] is valid. - Look at the preview. To try another colour, change
"default": "theme:accent"on line 34 to a colour such as"#3B2A1A"and save.
Hero
The big band at the top of the home page: a small label, a large heading, a sentence and two buttons.
<hk-section background="{{ section.settings.background }}" padding-y="112" tablet-padding-y="80" mobile-padding-y="56">
<hk-stack gap="20" mobile-gap="14" align="start">
{% if section.settings.eyebrow %}
<hk-badge text="{{ section.settings.eyebrow }}" tone="accent" />
{% endif %}
<hk-heading
text="{{ section.settings.title }}"
level="h1"
size="56"
tablet-size="44"
mobile-size="32"
color="#FFFFFF"
/>
<hk-text text="{{ section.settings.subtitle }}" size="20" mobile-size="16" color="#E5E7EB" />
<hk-stack direction="row" mobile-direction="column" gap="12">
<hk-button label="{{ section.settings.cta_label }}" href="{{ section.settings.cta_link }}" />
<hk-button label="{{ t('browse_all') }}" href="/collections/all" variant="outline" class="hero-outline" />
</hk-stack>
</hk-stack>
</hk-section>
<hk-schema>
{
"name": "Promo hero",
"version": 1,
"settings": {
"eyebrow": {
"type": "text",
"label": "Eyebrow",
"default": "New this week",
"maxLength": 40
},
"title": {
"type": "text",
"label": "Title",
"default": "Everything for your home, in one place",
"maxLength": 80
},
"subtitle": {
"type": "textarea",
"label": "Subtitle",
"default": "Delivery across Egypt. Pay cash when your order arrives.",
"maxLength": 200
},
"cta_label": {
"type": "text",
"label": "Button label",
"default": "Shop new arrivals",
"maxLength": 30
},
"cta_link": {
"type": "link",
"label": "Button link",
"default": "/collections/featured"
},
"background": {
"type": "color",
"label": "Background",
"default": "theme:primary"
}
}
}
</hk-schema>.sn-btn.hero-outline { color: #FFFFFF; border-color: #FFFFFF; }Add one line to locales/en.json:
{
"browse_all": "Browse all products"
}What each line does
- Line 1
<hk-section>is the band. The colour comes from thebackgroundsetting (lines 55-59), which starts as the theme'sprimarycolour. There are 112 px of space above and below the content: 80 px on tablets, 56 px on phones. - Line 2
<hk-stack>puts everything in a column, 20 px apart, lined up at the start of the line (the left, in an English store). - Lines 3-5 shows the small label only if the merchant wrote one. An empty setting counts as "no", so the badge disappears instead of showing empty.
- Lines 6-13
<hk-heading>is the page's main title (level="h1"), 56 px on desktop, 44 px on tablets, 32 px on phones, in white. - Line 14
<hk-text>is the sentence under the title, in light grey. - Lines 15-18 a row of two buttons that stack on phones. The first button's
text and link come from settings. The second button's text comes from the
locale files through
t('browse_all'), so it changes with the store's language. - Line 17
variant="outline"draws a button with a border and no fill.class="hero-outline"lets the CSS file make it white, so it shows on the dark band. - Lines 21-62 the settings: label, title, sentence, button text, button
link and background colour.
"type": "link"means an unsafe link (such asjavascript:…) is replaced with#before it reaches the page.
Try it
- Save the three files and add
{"type":"promo-hero"}to the template. - Run
validate, then look at the preview. - Change the window width: under 1024 px the heading is 44 px, under 640 px it is 32 px and the buttons stack.
Feature row
Three short cards side by side that tell shoppers why to buy here: delivery, payment and returns.
<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" align="center" />
<hk-grid columns="3" tablet-columns="1" gap="16">
<hk-card border="true" padding="24" radius="16">
<hk-stack gap="8">
<hk-heading text="{{ section.settings.one_title }}" level="h3" size="20" />
<hk-text text="{{ section.settings.one_text }}" size="15" color="#4B5563" />
</hk-stack>
</hk-card>
<hk-card border="true" padding="24" radius="16">
<hk-stack gap="8">
<hk-heading text="{{ section.settings.two_title }}" level="h3" size="20" />
<hk-text text="{{ section.settings.two_text }}" size="15" color="#4B5563" />
</hk-stack>
</hk-card>
<hk-card border="true" padding="24" radius="16">
<hk-stack gap="8">
<hk-heading text="{{ section.settings.three_title }}" level="h3" size="20" />
<hk-text text="{{ section.settings.three_text }}" size="15" color="#4B5563" />
</hk-stack>
</hk-card>
</hk-grid>
</hk-stack>
</hk-section>
<hk-schema>
{
"name": "Feature row",
"version": 1,
"settings": {
"heading": {
"type": "text",
"label": "Heading",
"default": "Why people shop with us"
},
"one_title": {
"type": "text",
"label": "Feature 1",
"default": "Delivery to every governorate"
},
"one_text": {
"type": "textarea",
"label": "Feature 1 text",
"default": "Cairo and Giza in 2 days, the rest of Egypt in 3 to 5."
},
"two_title": {
"type": "text",
"label": "Feature 2",
"default": "Cash on delivery"
},
"two_text": {
"type": "textarea",
"label": "Feature 2 text",
"default": "Pay when the order reaches your door."
},
"three_title": {
"type": "text",
"label": "Feature 3",
"default": "14-day returns"
},
"three_text": {
"type": "textarea",
"label": "Feature 3 text",
"default": "Not the right fit? Send it back within 14 days."
}
}
}
</hk-schema>What each line does
- Line 1 the section, with 64 px of space above and below (40 px on phones).
- Line 3 the heading, centred.
- Line 4
<hk-grid columns="3">makes three equal columns. On tablets and phones (tablet-columns="1") the cards stack in one column. - Lines 5-10 one card.
border="true"draws a thin border,padding="24"is the space inside it andradius="16"rounds the corners. Inside, a title and a sentence, both from settings. - Lines 11-22 the second and third cards, the same shape with their own settings.
- Lines 26-68 seven settings: the heading, then a title and a sentence for each card.
When the merchant should choose how many cards. Three fixed cards keep this example short. To let the merchant add and remove cards, make each card a block: see Sections and blocks.
Try it
Save the file, add {"type":"feature-row"} to the template, run validate and
look at the preview.
Product grid
A heading with a "View all" link, then the first products of the store's
featured collection in a grid. If the collection is empty, a short message
shows instead.
<hk-section padding-y="64" mobile-padding-y="40">
<hk-stack gap="24">
<hk-stack direction="row" justify="between" align="center">
<hk-heading text="{{ section.settings.heading }}" level="h2" size="32" mobile-size="24" />
{% if section.settings.show_link %}
<hk-button label="{{ t('view_all') }}" href="/collections/featured" variant="ghost" />
{% endif %}
</hk-stack>
{% if collection('featured').products %}
<hk-product-grid
products="{{ collection('featured').products }}"
limit="{{ section.settings.count }}"
columns="4"
tablet-columns="3"
mobile-columns="2"
/>
{% else %}
<hk-text text="{{ t('collection_empty') }}" align="center" />
{% endif %}
</hk-stack>
</hk-section>
<hk-schema>
{
"name": "Product grid",
"version": 1,
"settings": {
"heading": {
"type": "text",
"label": "Heading",
"default": "Best sellers"
},
"count": {
"type": "range",
"label": "Products to show",
"default": 4,
"min": 2,
"max": 24,
"step": 1
},
"show_link": {
"type": "boolean",
"label": "Show “View all”",
"default": true
}
}
}
</hk-schema>Add to locales/en.json:
{
"view_all": "View all",
"collection_empty": "No products here yet"
}What each line does
- Lines 3-8 a row with the heading at one end and the "View all" button at
the other (
justify="between"). The button shows only when theshow_linksetting is on.variant="ghost"is a button with no border and no fill. - Line 9
collection('featured').productsis the list of products in the collection whose handle isfeatured.{% if … %}is true when that list has at least one product. - Lines 10-16
<hk-product-grid>draws a card for each product: picture, name and price.limitis how many to show, from thecountsetting. Four columns on desktop, three on tablets, two on phones. - Lines 17-19 what shows when the collection is empty.
- Lines 32-39
countis a slider ("type": "range") from 2 to 24, starting at 4.
Note. The collection handle (
featured) is written in the template. A lookup only takes fixed text, socollection(section.settings.handle)is an error (SN1105). Use one section per collection.
Try it
- Save the file, add the locale lines and
{"type":"product-grid"}. - The preview shows the six sample products; the grid shows four.
- To see the empty message, change
featuredtosaleon lines 9 and 11 and save: the preview has nosalecollection.
Subscription plans
Three plans side by side with their monthly price. The merchant picks which one is the best value; that card gets a badge, a coloured outline and a filled button. Three files: the section, the card (a snippet, written once and used three times) and the outline's CSS.
<hk-section padding-y="64" mobile-padding-y="40">
<hk-stack gap="32">
<hk-heading text="{{ section.settings.heading }}" level="h2" size="32" mobile-size="24" align="center" />
<hk-grid columns="3" tablet-columns="1" gap="24">
{% render 'plan-card', name: section.settings.plan1_name, price: section.settings.plan1_price, details: section.settings.plan1_details, best: section.settings.best == '1', variant: 'outline' %}
{% render 'plan-card', name: section.settings.plan2_name, price: section.settings.plan2_price, details: section.settings.plan2_details, best: section.settings.best == '2', variant: 'solid' %}
{% render 'plan-card', name: section.settings.plan3_name, price: section.settings.plan3_price, details: section.settings.plan3_details, best: section.settings.best == '3', variant: 'outline' %}
</hk-grid>
</hk-stack>
</hk-section>
<hk-schema>
{
"name": "Subscription plans",
"version": 1,
"settings": {
"heading": {
"type": "text",
"label": "Heading",
"default": "Pick your monthly coffee box"
},
"plan1_name": {
"type": "text",
"label": "Plan 1 name",
"default": "Small"
},
"plan1_price": {
"type": "number",
"label": "Plan 1 price (piastres)",
"default": 29900,
"min": 0
},
"plan1_details": {
"type": "textarea",
"label": "Plan 1 details",
"default": "250 g of coffee, one roast"
},
"plan2_name": {
"type": "text",
"label": "Plan 2 name",
"default": "Regular"
},
"plan2_price": {
"type": "number",
"label": "Plan 2 price (piastres)",
"default": 49900,
"min": 0
},
"plan2_details": {
"type": "textarea",
"label": "Plan 2 details",
"default": "500 g of coffee, two roasts"
},
"plan3_name": {
"type": "text",
"label": "Plan 3 name",
"default": "Family"
},
"plan3_price": {
"type": "number",
"label": "Plan 3 price (piastres)",
"default": 79900,
"min": 0
},
"plan3_details": {
"type": "textarea",
"label": "Plan 3 details",
"default": "1 kg of coffee, any roasts"
},
"best": {
"type": "select",
"label": "Best value plan",
"options": ["1", "2", "3"],
"default": "2"
}
}
}
</hk-schema><hk-card class="plan" data-best="{{ best }}" padding="28" mobile-padding="20" radius="16" border="true">
<hk-stack gap="12" align="start">
{% if best %}
<hk-badge text="{{ t('best_value') }}" tone="accent" />
{% endif %}
<hk-heading text="{{ name }}" level="h3" size="22" />
<p class="plan-price"><strong>{{ price | money }}</strong> <small>{{ t('per_month') }}</small></p>
<hk-text text="{{ details }}" size="15" />
<hk-button label="{{ t('choose_plan') }}" href="/pages/subscribe" variant="{{ variant }}" />
</hk-stack>
</hk-card>.plan[data-best="true"] { outline: 2px solid var(--hk-color-accent); outline-offset: -2px; }
.plan-price { margin: 0; font-size: 28px; }
.plan-price small { font-size: 14px; opacity: .7; }Add to locales/en.json:
{
"best_value": "Best value",
"per_month": "/ month",
"choose_plan": "Choose this box"
}What each line does
In sections/pricing.snf:
- Line 4 a three-column grid that becomes one column on tablets and phones.
- Lines 5-7
{% render 'plan-card', … %}drawssnippets/plan-card.snfthree times, each time with its own values:name,price,details,bestandvariant.best: section.settings.best == '1'istrueonly for the plan the merchant chose as the best value. - Lines 26-31, 42-47, 58-63 prices are whole numbers in piastres:
29900is EGP 299.00. Never write299.00in a price setting. - Lines 69-74 a drop-down (
"type": "select") with the choices 1, 2 and 3.
In snippets/plan-card.snf:
- Line 1 the card.
data-best="{{ best }}"writestrueorfalseinto the page, so the CSS file can draw an outline around the best card only. - Lines 3-5 the "Best value" badge, only on the best card.
- Line 7
{{ price | money }}turns29900intoEGP 299.00. - Line 9 the button: filled on the best card, outlined on the others, as
the section passed in
variant.
Note. A
style="…"attribute cannot contain{{ }}. To style a card by its state, write the state into adata-*attribute, as line 1 of the snippet does, and match it in CSS.
Try it
- Save the four files, add
{"type":"pricing"}to the template, and runvalidate. - To mark another plan as the best value, change
"default": "2"on line 73 to"3"and save.
All five on one page
With all five types listed in templates/index.snf, the preview shows a
complete home page. Arrange them in any order; the merchant can reorder them
later in the store builder.
<hk-sections />
<hk-schema>
{
"sections": [
{
"type": "announcement-bar"
},
{
"type": "promo-hero"
},
{
"type": "feature-row"
},
{
"type": "product-grid"
},
{
"type": "pricing"
}
]
}
</hk-schema>