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

Hero section

The starter theme hero section from Sneferu, with its complete code, the settings a merchant can change and how each tag works.

On this page

What you'll build

A big heading, a line of text and a button over a coloured band, with an optional image. The Result below is drawn by the real Sneferu renderer from the code on this page.

Result

Requirements

  • Node.js 20 or newer
  • A theme made with npx sneferu init. Every file below is part of it.
  • The preview running: npx sneferu dev

Code

Concepts this teaches: Sections, Settings, Blocks, Locale fallback, Snippets.

These files come from the starter theme that npx sneferu init creates. The example is sections/hero.snf.

sections/hero.snfSneferu
<hk-section
  background="{{ section.settings.background }}"
  padding-y="{{ section.settings.padding_y }}"
  mobile-padding-y="48"
>
  <div class="sf-hero sf-align-{{ section.settings.align }}">
    <div class="sf-hero-text">
      {% for block in section.blocks %}<hk-block of="{{ block }}" />{% endfor %}
      <hk-heading
        text="{{ section.settings.title | default: t('hero_title') }}"
        level="h1"
        size="52"
        mobile-size="32"
        color="{{ section.settings.text_color }}"
      />
      <hk-text
        text="{{ section.settings.subtitle | default: t('hero_text') }}"
        size="20"
        color="{{ section.settings.text_color }}"
      />
      {% render 'button', label: section.settings.button_label, href: section.settings.button_link, style: section.settings.button_style %}
    </div>
    {% if section.settings.image %}
      <div class="sf-hero-media">
        <hk-image
          src="{{ section.settings.image }}"
          alt="{{ section.settings.image_alt }}"
          loading="eager"
          aspect-ratio="4/5"
          sizes="(min-width: 1024px) 40vw, 100vw"
        />
      </div>
    {% endif %}
  </div>
</hk-section>
<hk-schema>
  {
    "name": {
      "en": "Hero",
      "ar": "البانر الرئيسي"
    },
    "version": 1,
    "blocks": {
      "allowed": ["chip"],
      "max": 4
    },
    "settings": {
      "title": {
        "type": "text",
        "label": {
          "en": "Heading",
          "ar": "العنوان"
        },
        "default": "",
        "localized": true,
        "maxLength": 80
      },
      "subtitle": {
        "type": "textarea",
        "label": {
          "en": "Text",
          "ar": "النص"
        },
        "default": "",
        "localized": true,
        "maxLength": 200
      },
      "button_label": {
        "type": "text",
        "label": {
          "en": "Button",
          "ar": "الزر"
        },
        "default": {
          "ar": "تسوق دلوقتي",
          "en": "Shop now"
        },
        "localized": true,
        "maxLength": 30
      },
      "button_link": {
        "type": "link",
        "label": {
          "en": "Button link",
          "ar": "رابط الزر"
        },
        "default": "/products"
      },
      "button_style": {
        "type": "select",
        "label": {
          "en": "Button style",
          "ar": "شكل الزر"
        },
        "options": ["solid", "outline", "ghost"],
        "default": "solid"
      },
      "image": {
        "type": "image",
        "label": {
          "en": "Image",
          "ar": "الصورة"
        },
        "default": ""
      },
      "image_alt": {
        "type": "text",
        "label": {
          "en": "Image description",
          "ar": "وصف الصورة"
        },
        "default": "",
        "localized": true,
        "maxLength": 120
      },
      "align": {
        "type": "select",
        "label": {
          "en": "Text alignment",
          "ar": "محاذاة النص"
        },
        "options": ["start", "center"],
        "default": "start"
      },
      "background": {
        "type": "color",
        "label": {
          "en": "Background",
          "ar": "الخلفية"
        },
        "default": "theme:secondary"
      },
      "text_color": {
        "type": "color",
        "label": {
          "en": "Text colour",
          "ar": "لون النص"
        },
        "default": "theme:background"
      },
      "padding_y": {
        "type": "range",
        "label": {
          "en": "Vertical padding",
          "ar": "المسافة الرأسية"
        },
        "min": 0,
        "max": 200,
        "step": 8,
        "default": 88
      }
    }
  }
</hk-schema>
snippets/button.snfSneferu
{% if label %}<hk-button label="{{ label }}" href="{{ href }}" variant="{{ style }}" />{% endif %}

Download: sections/hero.snf, snippets/button.snf in the public SDK repo at commit c96cbf2, or the whole starter theme folder.

Preview

Result

Customize

Settings in the hk-schema of sections/hero.snf. The merchant changes them in the theme editor; the default is what a new section starts with.

SettingLabelTypeDefaultNotes
titleHeadingtextset per language
subtitleTexttextareaset per language
button_labelButtontext&#123;"ar":"تسوق دلوقتي","en":"Shop now"&#125;set per language
button_linkButton linklink/products
button_styleButton styleselectsolidone of solid, outline, ghost
imageImageimage
image_altImage descriptiontextset per language
alignText alignmentselectstartone of start, center
backgroundBackgroundcolortheme:secondary
text_colorText colourcolortheme:background
padding_yVertical paddingrange880 to 200 in steps of 8

Text keys the code reads with t(). Change the English text in locales/en.json and the Arabic text under the same key in locales/ar.json.

KeyEnglish text
hero_titleEverything you need, in one place
hero_textPick what you like and check out in a minute.

How it works

  • This code uses the tags hk-section, hk-block, hk-heading, hk-text, hk-image, hk-button.
  • hk-section is the band: its background and padding-y come from the section settings, and mobile-padding-y tightens it on a phone.
  • hk-heading and hk-text print the title and subtitle. default: t('hero_title') falls back to the language file when the merchant leaves the setting empty (see Filters).
  • hk-block prints each block the merchant adds, here the chip badges the schema allows (see Blocks).
  • {% render 'button' %} calls the button snippet shown below the hero, so the button looks the same everywhere.
  • hk-image only appears when an image is set: the {% if section.settings.image %} guard keeps the layout clean without one.

Next steps