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

Data and expressions

What a Sneferu template can read: scope, lookups, product fields, output, expressions, truthiness, filters, loops and translations.

On this page

Templates read data with {{ expression }} and control output with {% if %}, {% for %} and {% render %}. There is no arithmetic, no assignment and no function calls besides the lookups below: a template cannot run code. The full grammar is in language.md.

What a template can read

NameWhereContains
storeeverywherethe store, e.g. store.name
settingseverywheretheme settings from theme.json settings, defaults filled in and coerced: settings.accent
sectionsections, their blocks and snippetssection.id, section.type, section.settings.*, section.blocks
blockblocksblock.id, block.type, block.settings.*
localeeverywherear or en
direverywherertl (Arabic) or ltr
forloopinside {% for %}forloop.index (from 1), forloop.first, forloop.last
loop variable, render argumentswhere you name theme.g. p in {% for p in … %}

Lookups

Lookups take literal arguments (collection('featured')). Some take more: collection() also takes a collection setting, so the merchant can choose the collection (see Let the merchant choose a collection), product() a product setting, menu() a menu setting (see Menus), and url() takes any one expression (see Links). Any other argument, such as collection(product.title), is SN1105.

LookupReturns
collection('featured')the collection: .title, .products. A missing collection is { products: [] }, never an error
collection('related')on a product page, the other products of the current product's category (the product itself left out, at most 8); empty elsewhere. This is how a theme shows related products, since collection(product.category.handle) is SN1105
collection(section.settings.list)the collection the merchant picked in a collection setting; an empty collection when none is picked
collections()the store's categories (at most 50), see List the store's categories
product('handle')the product, or nothing
menu('main')the store's menu: .title, .items (each { title, url, active, child_active, children }). Takes a handle or a menu setting: menu(section.settings.menu). A missing menu is { handle, title: '', items: [] }, never an error. See Menus
t('shop_now')the text from locales/<locale>.json, then the default locale, then the key itself
settings('accent')one theme setting (same as settings.accent)
asset_url('logo.svg')the URL of assets/logo.svg
url('/products')a link for this page: /en/products on an English page, /products on an Arabic one. Takes a literal or any expression: url(section.settings.link)

Product fields

A product (from collection(…).products or product(…)) has:

FieldExample
id"8f1c…" (stable; do not show it)
handleps-card
titlePlayStation gift card
url/products/ps-card
price52000 (minor units: piastres; 52000 = 520.00 EGP)
compare_at60000 or nil (the price before a discount)
image{ url: "https://…" }
availabletrue when it can be bought
description<p>The code arrives <strong>by email</strong>.</p>: sanitised HTML in the page's language. {{ product.description }} prints it escaped, as text; output it as HTML with <hk-rich-text html="{{ product.description }}" />
excerptThe code arrives by email. (plain text, at most 200 characters)
kindphysical or digital
digital_kindcode, file or manual for a digital product; nil for a physical one
tags["gift-card", "gaming"] (at most 20, each at most 40 characters)
category{ handle: "gift-cards", title: "Gift cards", url: "/category/gift-cards" }, or nil
html
<hk-product-card product="{{ p }}">
  <hk-part name="badge">{% if p.kind == 'digital' %}<span class="tag">{{ 'instant' | t }}</span>{% endif %}</hk-part>
</hk-product-card>
<hk-rich-text html="{{ product.description }}" />
<p>{{ product.excerpt }}</p>

In sneferu dev every sample product has all of these fields.

Output

html
<h2>{{ section.settings.title }}</h2>
<p>{{ store.name }} · {{ t('shop_now') }}</p>
<a class="card {{ section.settings.tone }}" href="{{ p.url }}">{{ p.title }}</a>
  • Output is escaped for where it lands: text, attribute or URL. You cannot inject HTML through a setting.
  • URL attributes (href, src, …) go through a safe-URL check: javascript: and other unsafe values become #.
  • Dynamic class and id are reduced to letters, digits, -, _ and spaces.
  • Strings, numbers and booleans print as text (true); objects and arrays print nothing. Missing data prints nothing; it never throws.
  • An attribute can mix text and expressions: class="tier {{ section.settings.size }}".
  • On hk-* tags, an attribute that is exactly one {{ }} passes the raw value (a number, an array of products, an object). Mixed text makes a string.

Expressions

FormExample
Literals'text', "text", 42, true, false, nil
Propertysection.settings.title, p.image.url
Indexcollection('featured').products[0].title
Sizesection.blocks.size, p.title.size
Compare==, != (strict), >, <, >=, <= (numbers only; false otherwise)
Logicand, or, not, parentheses
Filtersvalue | filter, value | filter: arg1, arg2
html
{% if p.compare_at > p.price %}<hk-badge text="{{ t('sale') }}" tone="warning" />{% endif %}
{% if section.settings.layout == 'wide' and not section.settings.compact %}…{% endif %}

>/< compare numbers only: '10' > 9 is false. Prices are numbers, so price comparisons work.

Truthiness

In {% if %}, {% elsif %}, and, or, not:

FalseTrue
nil (missing), false, 0, '' (empty string), [] (empty array)everything else, including '0', ' ' and {}

So {% if collection('featured').products %} is false for an empty or missing collection, and {% if section.blocks %} is false when the merchant added no blocks. Use that for empty states:

html
{% if collection('featured').products %}
  <hk-product-grid products="{{ collection('featured').products }}" />
{% else %}
  <hk-text text="{{ t('collection_empty') }}" align="center" />
{% endif %}

{% else %} comes once, last (SN1109).

Filters

FilterInput → output
moneyprice in minor units → formatted price in the store currency. {{ 129000 | money }} → EGP 1,290.00. Other currencies use the ISO code: USD 1,290.00. On an Arabic page the currency comes after the number. Western digits. Options: see Money formats
imgimage (object with url, or a URL) → image URL, optionally sized: {{ p.image | img: 400 }}
dateISO date → long date: {{ '2026-10-10' | date }} → 10 October 2026
tkey → translation: {{ 'shop_now' | t }} (same as t('shop_now'))
upcase / downcase{{ 'egp' | upcase }} → EGP
truncate{{ p.title | truncate: 20 }} → at most 20 characters, ending in … (default 50)
default{{ section.settings.eyebrow | default: 'New' }} → the fallback when the value is nil or ''
size{{ section.blocks | size }} → 3 (arrays and strings; 0 otherwise)
first / lastfirst / last array item: {{ tags | first }}. A filter result cannot be followed by .property; for a field of the first product write collection('featured').products[0].title
join{{ tags | join: ' · ' }} → a · b (default separator , ). On a missing value it prints its argument, so guard it: {% if tags %}…{% endif %}
escapeconverts to a string (output is escaped anyway)
json_attrvalue → JSON for a data-* attribute: data-ids="{{ ids | json_attr }}"
tag_valuestags → the values of the tags written prefix:value: {% for n in product.tags | tag_values: 'top' %}…{% endfor %} lists Bergamot for the tag top:Bergamot. The prefix match ignores case; values are trimmed; empty and repeated ones are dropped; at most 20. A value may carry its Arabic after a bar (top:Bergamot|برغموت): Arabic pages show the part after the bar, English pages the part before it

Filters chain left to right: {{ p.title | truncate: 30 | upcase }}.

Prices are always integers in minor units. Never divide or format them yourself; use money or <hk-price amount="{{ p.price }}" compare-at="{{ p.compare_at }}" />.

Dates and prices always use Western digits, in every locale, matching the rest of Hekana.

Money formats

money takes two optional arguments: the format and the unit.

ExpressionArabic pageEnglish page
{{ 129000 | money }}1,290.00 ج.مEGP 1,290.00
{{ 129000 | money: 'whole' }}1,290 ج.مEGP 1,290
{{ 129050 | money: 'whole' }}1,290.50 ج.مEGP 1,290.50
{{ 120 | money: 'whole', 'major' }}120 ج.مEGP 120
  • Format: 'decimal' (the default) always prints two decimals; 'whole' drops .00 when the amount is a whole pound and keeps two decimals otherwise.
  • Unit: 'minor' (the default) reads the input as piastres; 'major' reads it as pounds. Product prices are always minor units, so 'major' is for numbers you wrote yourself. The unit is the second argument, so 'major' always needs a format before it: money: 'decimal', 'major' or money: 'whole', 'major'.

To make whole the default for the whole theme, set it in theme.json:

json
"money": { "format": "whole" }

It applies to money without a format, to <hk-price> and to the price inside <hk-product-card> and <hk-product-grid>. <hk-price format="decimal"> (or "whole") overrides it for one tag, and money: 'decimal' for one expression. With the whole format <hk-price> wraps the number in <bdi>, so it reads correctly next to ج.م on Arabic pages; with the default format its markup is unchanged. Anything other than decimal or whole in theme.json is SN3033.

A link written in a template is used as written: href="/products" goes to the Arabic page even when the shopper is on English. Wrap store links in url() so they keep the page's language:

html
<a href="{{ url('/products') }}">{{ t('all_products') }}</a>
<a href="{{ url(section.settings.link) }}">{{ section.settings.label }}</a>
On an English pageResult
url('/products')/en/products
url('/en/products')/en/products (already prefixed)
url('https://example.com'), url('mailto:…'), url('tel:…'), url('#reviews')unchanged
url('javascript:…'), url('//evil.example'), an empty value#

On an Arabic page store paths are unchanged (Arabic is the default language and has no prefix). On the store, Hekana also adds whatever the store's address needs; the result is always checked with the same URL rules as href (see Security and limits). url() takes exactly one argument.

<hk-button href="/products"> does this for you: its link always follows the page's language. Product and category URLs (p.url, c.url) already include the prefix, so they do not need url().

Loops

A short list of the first three products of a collection, numbered, with a "Sale" label on any product that has a lower price than before.

sections/on-sale.snfSneferu
<hk-section padding-y="64" mobile-padding-y="40">
  <hk-stack gap="16">
    <hk-heading text="{{ section.settings.heading }}" level="h2" size="32" mobile-size="24" />
    {% for p in collection('featured').products limit: 3 %}
      <hk-card border="true" padding="16" radius="12">
        <hk-stack direction="row" justify="between" align="center" gap="12">
          <hk-text text="{{ forloop.index }}. {{ p.title }}" size="17" />
          <hk-stack direction="row" gap="8" align="center">
            {% if p.compare_at > p.price %}
              <hk-badge text="{{ t('sale') }}" tone="accent" />
            {% endif %}
            <hk-price amount="{{ p.price }}" compare-at="{{ p.compare_at }}" />
          </hk-stack>
        </hk-stack>
      </hk-card>
    {% endfor %}
  </hk-stack>
</hk-section>
<hk-schema>
  {
    "name": "Product list",
    "version": 1,
    "settings": {
      "heading": {
        "type": "text",
        "label": "Heading",
        "default": "Today's picks"
      }
    }
  }
</hk-schema>
Result
1080 px wide, English. The product names are the dev preview's sample data.

What each line does

  1. Line 4 {% for p in collection('featured').products limit: 3 %} repeats lines 5-15 once for each of the first three products. Inside, p is the current product.
  2. Line 7 {{ forloop.index }} is 1, 2, 3 and {{ p.title }} is the product's name.
  3. Lines 9-11 p.compare_at > p.price is true when the product had a higher price before; only then the "Sale" badge shows. Its words come from the sale key in your locale files, and its look from the badge rules in the starter's assets/theme.css.
  4. Line 12 <hk-price> prints the price, and the old price crossed out when there is one.
  5. Line 16 {% endfor %} ends the repeated part.
RuleValue
Default limit (no limit:)50 items
Largest limit:250 (a limit below 1 or above 250 is SN2007)
Iterations per page, all loops together2,000
Looping over something that is not an arrayrenders nothing
forloop.index1, 2, 3 …
forloop.first / forloop.lasttrue on the first / last item

There is no forloop.length; use {{ list | size }} or list.size.

Loop limits from settings

limit: may also read a number or range setting, so the merchant chooses how many items show:

html
{% for p in collection('featured').products limit: section.settings.count %}

The setting is section.settings.<name>, block.settings.<name> or settings.<name>; anything else is SN1105, and a setting that does not exist or is not a number or range is SN2012. At render time a value above 250 uses 250, and a value below 1 or not a whole number (empty, text, 2.5, 0, -3) uses the default limit, 50.

Let the merchant choose a collection

A collection setting gives the merchant a collection picker in the builder. Pass the setting to collection() and the section shows whatever they pick:

sections/collection-shelf.snfSneferu
<hk-section padding-y="48">
  <hk-stack gap="16">
    <hk-heading text="{{ collection(section.settings.list).title }}" level="h2" />
    {% for p in collection(section.settings.list).products limit: section.settings.count %}
      <hk-product-card product="{{ p }}" />
    {% endfor %}
  </hk-stack>
</hk-section>
<hk-schema>
  {
    "name": "Collection shelf",
    "version": 1,
    "settings": {
      "list": {
        "type": "collection",
        "label": "Collection",
        "default": "featured"
      },
      "count": {
        "type": "range",
        "label": "Products",
        "min": 1,
        "max": 12,
        "default": 4
      }
    }
  }
</hk-schema>
RuleValue
Argumenta handle in quotes, or section.settings.<name>, block.settings.<name>, settings.<name>
The settingmust exist and be of type collection (SN2012). In a section file block.settings.* is not checked, because the block type is only known on the page
Nothing picked (empty value)an empty collection: the loop renders nothing, nothing is fetched
Before renderingthe store fetches every collection the page can show, the picked ones and their defaults included, up to 8 per page

List the store's categories

collections() takes no arguments and returns the store's categories, at most 50, for a category menu or a grid of category tiles:

html
<nav>
  {% for c in collections() %}
    <a href="{{ c.url }}">{{ c.title }} ({{ c.count }})</a>
  {% endfor %}
</nav>
FieldExample
handlegift-cards
titleGift cards (in the page's language)
url/en/category/gift-cards (with the language prefix of the page)
image{ url: "https://…" }, or nil when the category has no image
count6 (the number of products)
parentthe handle of the parent category, or nil for a top-level one
childrenthe sub-categories of this one (each with the same fields), empty when it has none

collections() lists every category flat, sub-categories included. To show a tree, list the top-level ones and walk their children:

html
{% for c in collections() %}
  {% if not c.parent %}
    <a href="{{ c.url }}">{{ c.title }}</a>
    {% for s in c.children %}<a href="{{ s.url }}">{{ s.title }}</a>{% endfor %}
  {% endif %}
{% endfor %}

A store with no categories returns an empty list. In sneferu dev the sample store has three categories: new, gift-cards and subscriptions.

Translations

html
<hk-button label="{{ t('shop_now') }}" href="/products" />
<span>{{ 'free_delivery' | t }}</span>

Use t() for interface words and settings for merchant content. A page uses locales/<locale>.json and falls back to the default locale for any missing key.

Snippet arguments

html
{% render 'plan-card', name: section.settings.plan1_name, price: section.settings.plan1_price, best: section.settings.best == '1' %}

The subscription plans in the cookbook use this. Arguments are key: expression, separated by commas (commas inside quotes are fine: label: 'a, b'). The snippet sees them plus the caller's scope.

Next steps