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

Product details

The starter theme product section from Sneferu with the blocks for title, price, variants and buy button, with its complete code.

On this page

What you'll build

The product page: gallery, breadcrumb and an info column built from blocks. 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: Page types, Blocks, Product gallery, Variants, Add to cart.

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

sections/product-main.snfSneferu
<hk-section padding-y="{{ section.settings.padding_y }}" mobile-padding-y="24">
  {% if section.settings.show_breadcrumb %}
    <nav class="sf-breadcrumb" aria-label="{{ t('breadcrumb') }}">
      <a href="{{ url('/') }}">{{ t('home') }}</a>
      {% if product.category %}
        <span aria-hidden="true">/</span>
        <a href="{{ product.category.url }}">{{ product.category.title }}</a>
      {% endif %}
      <span aria-hidden="true">/</span>
      <span aria-current="page">{{ product.title }}</span>
    </nav>
  {% endif %}
  <div class="sf-product sf-gallery-{{ section.settings.gallery_side }} sf-sticky-{{ section.settings.sticky_info }}">
    <div class="sf-product-gallery">
      <hk-product-gallery product="{{ product }}" layout="{{ section.settings.gallery_layout }}" />
    </div>
    <div class="sf-product-info" role="group" aria-label="{{ t('product_info') }}">
      {% for block in section.blocks %}<hk-block of="{{ block }}" />{% endfor %}
    </div>
  </div>
</hk-section>
<hk-schema>
  {
    "name": {
      "en": "Product",
      "ar": "المنتج"
    },
    "version": 1,
    "templates": ["product"],
    "blocks": {
      "allowed": [
        "product-title",
        "product-price",
        "product-excerpt",
        "product-variants",
        "product-buy",
        "product-description",
        "product-tags",
        "product-category",
        "product-text"
      ],
      "max": 20
    },
    "settings": {
      "gallery_layout": {
        "type": "select",
        "label": {
          "en": "Gallery layout",
          "ar": "شكل المعرض"
        },
        "options": ["thumbs-below", "thumbs-side", "stacked"],
        "default": "thumbs-below"
      },
      "gallery_side": {
        "type": "select",
        "label": {
          "en": "Gallery position",
          "ar": "مكان الصور"
        },
        "options": ["start", "end"],
        "default": "start"
      },
      "sticky_info": {
        "type": "boolean",
        "label": {
          "en": "Keep the details in view while scrolling",
          "ar": "تثبيت التفاصيل أثناء التمرير"
        },
        "default": false
      },
      "show_breadcrumb": {
        "type": "boolean",
        "label": {
          "en": "Show breadcrumb",
          "ar": "إظهار مسار الصفحة"
        },
        "default": true
      },
      "padding_y": {
        "type": "range",
        "label": {
          "en": "Vertical padding",
          "ar": "المسافة الرأسية"
        },
        "min": 0,
        "max": 160,
        "step": 8,
        "default": 40
      }
    }
  }
</hk-schema>
blocks/product-title.snfSneferu
<hk-heading
  text="{{ product.title }}"
  level="{{ block.settings.level }}"
  size="{{ block.settings.size }}"
  mobile-size="{{ block.settings.mobile_size }}"
/>
<hk-schema>
  {
    "name": {
      "en": "Title",
      "ar": "العنوان"
    },
    "version": 1,
    "settings": {
      "level": {
        "type": "select",
        "label": {
          "en": "Heading level",
          "ar": "مستوى العنوان"
        },
        "options": ["h1", "h2", "h3"],
        "default": "h1"
      },
      "size": {
        "type": "range",
        "label": {
          "en": "Size",
          "ar": "الحجم"
        },
        "min": 18,
        "max": 64,
        "default": 32
      },
      "mobile_size": {
        "type": "range",
        "label": {
          "en": "Size on phones",
          "ar": "الحجم على الموبايل"
        },
        "min": 16,
        "max": 48,
        "default": 26
      }
    }
  }
</hk-schema>
blocks/product-price.snfSneferu
<div class="sf-price-row">
  {% render 'price', product: product, bind: true %}
  {% if block.settings.show_badge %}
    {% if product.available %}
      {% if product.compare_at > product.price %}<span class="sf-badge">{{ t('sale') }}</span>{% endif %}
    {% else %}
      <span class="sf-badge sf-badge-muted">{{ t('sold_out_badge') }}</span>
    {% endif %}
  {% endif %}
</div>
<hk-schema>
  {
    "name": {
      "en": "Price",
      "ar": "السعر"
    },
    "version": 1,
    "settings": {
      "show_badge": {
        "type": "boolean",
        "label": {
          "en": "Show sale and sold out badge",
          "ar": "إظهار شارة الخصم ونفاد المخزون"
        },
        "default": true
      }
    }
  }
</hk-schema>
blocks/product-variants.snfSneferu
<hk-variant-picker product="{{ product }}" display="{{ block.settings.style }}" />
<hk-schema>
  {
    "name": {
      "en": "Variant picker",
      "ar": "اختيار النوع"
    },
    "version": 1,
    "settings": {
      "style": {
        "type": "select",
        "label": {
          "en": "Style",
          "ar": "الشكل"
        },
        "options": ["auto", "swatches", "buttons", "select"],
        "default": "auto"
      }
    }
  }
</hk-schema>
blocks/product-buy.snfSneferu
<hk-add-to-cart
  product="{{ product }}"
  label="{{ block.settings.label }}"
  sold-out-label="{{ block.settings.sold_out_label }}"
  quantity="{{ block.settings.show_quantity }}"
  variant="{{ block.settings.button_style }}"
/>
<hk-schema>
  {
    "name": {
      "en": "Buy buttons",
      "ar": "زر الشراء"
    },
    "version": 1,
    "settings": {
      "label": {
        "type": "text",
        "label": {
          "en": "Button label (default: Add to cart)",
          "ar": "نص الزر (الافتراضي: أضف للسلة)"
        },
        "default": "",
        "localized": true,
        "maxLength": 30
      },
      "sold_out_label": {
        "type": "text",
        "label": {
          "en": "Sold out label",
          "ar": "نص نفاد المخزون"
        },
        "default": "",
        "localized": true,
        "maxLength": 30
      },
      "show_quantity": {
        "type": "boolean",
        "label": {
          "en": "Show quantity",
          "ar": "إظهار الكمية"
        },
        "default": true
      },
      "button_style": {
        "type": "select",
        "label": {
          "en": "Button style",
          "ar": "شكل الزر"
        },
        "options": ["solid", "outline"],
        "default": "solid"
      }
    }
  }
</hk-schema>

Download: sections/product-main.snf, blocks/product-title.snf, blocks/product-price.snf, blocks/product-variants.snf, blocks/product-buy.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/product-main.snf. The merchant changes them in the theme editor; the default is what a new section starts with.

SettingLabelTypeDefaultNotes
gallery_layoutGallery layoutselectthumbs-belowone of thumbs-below, thumbs-side, stacked
gallery_sideGallery positionselectstartone of start, end
sticky_infoKeep the details in view while scrollingbooleanfalse
show_breadcrumbShow breadcrumbbooleantrue
padding_yVertical paddingrange400 to 160 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
breadcrumbBreadcrumb
homeHome
product_infoProduct details

How it works

  • This code uses the tags hk-section, hk-product-gallery, hk-block, hk-heading, hk-variant-picker, hk-add-to-cart.
  • hk-product-gallery shows the product photos in the layout the merchant picks.
  • The information column is just {% for block in section.blocks %} with hk-block: the merchant orders the title, price, options and buy button blocks in the editor.
  • hk-variant-picker (in the variants block) and hk-add-to-cart (in the buy block) are the controls that choose an option and add it to the cart.
  • The breadcrumb reads product.category and prints text with t('breadcrumb') and t('home').
  • hk-heading in the title block prints the product title as the page heading.

Next steps