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

Collection page

The starter theme collection section from Sneferu: sort options, filters, a product grid and pagination, with its complete code.

On this page

What you'll build

A product listing with sorting, filters and pagination. 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, Sorting and filters, Loops, Pagination.

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

sections/collection-main.snfSneferu
<hk-section padding-y="{{ section.settings.padding_y }}" mobile-padding-y="24">
  <div class="sf-collection-head">
    {% if section.settings.show_title %}
      <hk-heading text="{{ collection.title }}" level="h1" size="32" mobile-size="26" />
    {% endif %}
    {% if section.settings.show_description %}
      {% if collection.description %}<hk-rich-text html="{{ collection.description }}" />{% endif %}
    {% endif %}
    {% if section.settings.show_count %}
      <p class="sf-muted">{{ collection.products_count }} {{ t('products_label') }}</p>
    {% endif %}
  </div>
  {% if section.settings.show_sort %}
    {% if collection.sort_options %}
      <div class="sf-toolbar">
        <span class="sf-muted">{{ t('sort_by') }}</span>
        {% for o in collection.sort_options %}
          <a class="sf-chip" href="{{ o.url }}" aria-current="{{ o.active }}">{{ o.label }}</a>
        {% endfor %}
      </div>
    {% endif %}
  {% endif %}
  {% if section.settings.show_filters %}
    {% if collection.filters %}
      <details class="sf-filters">
        <summary>{{ t('filters') }}</summary>
        {% for f in collection.filters %}
          <div class="sf-filter">
            <h2 class="sf-filter-name">{{ f.name }}</h2>
            {% for v in f.values %}
              <a class="sf-chip" href="{{ v.url }}" aria-current="{{ v.active }}">{{ v.label }}</a>
            {% endfor %}
          </div>
        {% endfor %}
      </details>
    {% endif %}
  {% endif %}
  {% if collection.products %}
    <div class="sf-grid sf-cols-{{ section.settings.columns }}">
      {% for p in collection.products limit: 48 %}
        {% render 'product-card', product: p, card_style: section.settings.card_style, image_ratio: section.settings.image_ratio, show_price: section.settings.show_price, show_badge: section.settings.show_badge %}
      {% endfor %}
    </div>
    <hk-pagination paginate="{{ paginate }}" />
  {% else %}
    <div class="sf-empty">
      {% if section.settings.empty_image %}
        <hk-image src="{{ section.settings.empty_image }}" alt="" width="240" />
      {% endif %}
      {% if section.settings.empty_title %}
        <h2 class="sf-empty-title">{{ section.settings.empty_title }}</h2>
      {% endif %}
      {% if section.settings.empty_text %}
        <p>{{ section.settings.empty_text }}</p>
      {% endif %}
      {% render 'button', label: section.settings.empty_button_label, href: section.settings.empty_button_link, style: section.settings.empty_button_style %}
    </div>
  {% endif %}
</hk-section>
<hk-schema>
  {
    "name": {
      "en": "Collection",
      "ar": "القسم"
    },
    "version": 1,
    "templates": ["collection"],
    "settings": {
      "show_title": {
        "type": "boolean",
        "label": {
          "en": "Show title",
          "ar": "إظهار العنوان"
        },
        "default": true
      },
      "show_description": {
        "type": "boolean",
        "label": {
          "en": "Show description",
          "ar": "إظهار الوصف"
        },
        "default": true
      },
      "show_count": {
        "type": "boolean",
        "label": {
          "en": "Show product count",
          "ar": "إظهار عدد المنتجات"
        },
        "default": true
      },
      "show_sort": {
        "type": "boolean",
        "label": {
          "en": "Show sort options",
          "ar": "إظهار خيارات الترتيب"
        },
        "default": true
      },
      "show_filters": {
        "type": "boolean",
        "label": {
          "en": "Show filters",
          "ar": "إظهار الفلاتر"
        },
        "default": true
      },
      "columns": {
        "type": "range",
        "label": {
          "en": "Columns",
          "ar": "الأعمدة"
        },
        "min": 2,
        "max": 5,
        "default": 4
      },
      "card_style": {
        "type": "select",
        "label": {
          "en": "Card style",
          "ar": "شكل الكارت"
        },
        "options": ["plain", "bordered", "shadow"],
        "default": "plain"
      },
      "image_ratio": {
        "type": "select",
        "label": {
          "en": "Image shape",
          "ar": "شكل الصورة"
        },
        "options": ["1/1", "4/5", "3/4"],
        "default": "1/1"
      },
      "show_price": {
        "type": "boolean",
        "label": {
          "en": "Show price",
          "ar": "إظهار السعر"
        },
        "default": true
      },
      "show_badge": {
        "type": "boolean",
        "label": {
          "en": "Show sale and sold out badge",
          "ar": "إظهار شارة الخصم ونفاد المخزون"
        },
        "default": true
      },
      "empty_image": {
        "type": "image",
        "label": {
          "en": "Empty state image",
          "ar": "صورة حالة القسم الفاضي"
        },
        "default": ""
      },
      "empty_title": {
        "type": "text",
        "label": {
          "en": "Empty state title",
          "ar": "عنوان القسم الفاضي"
        },
        "default": {
          "ar": "مفيش منتجات هنا لسه",
          "en": "No products here yet"
        },
        "localized": true,
        "maxLength": 80
      },
      "empty_text": {
        "type": "textarea",
        "label": {
          "en": "Empty state text",
          "ar": "نص القسم الفاضي"
        },
        "default": {
          "ar": "جرب قسم تاني أو ارجع للمتجر.",
          "en": "Try another collection or go back to the shop."
        },
        "localized": true,
        "maxLength": 200
      },
      "empty_button_label": {
        "type": "text",
        "label": {
          "en": "Empty state button",
          "ar": "زر القسم الفاضي"
        },
        "default": {
          "ar": "كل المنتجات",
          "en": "All products"
        },
        "localized": true,
        "maxLength": 30
      },
      "empty_button_link": {
        "type": "link",
        "label": {
          "en": "Empty state button link",
          "ar": "رابط زر القسم الفاضي"
        },
        "default": "/products"
      },
      "empty_button_style": {
        "type": "select",
        "label": {
          "en": "Empty state button style",
          "ar": "شكل زر القسم الفاضي"
        },
        "options": ["solid", "outline", "ghost"],
        "default": "solid"
      },
      "padding_y": {
        "type": "range",
        "label": {
          "en": "Vertical padding",
          "ar": "المسافة الرأسية"
        },
        "min": 0,
        "max": 160,
        "step": 8,
        "default": 40
      }
    }
  }
</hk-schema>
templates/collection.snfSneferu
<hk-sections />
<hk-schema>
  {
    "sections": [
      {
        "type": "collection-main"
      }
    ]
  }
</hk-schema>

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

SettingLabelTypeDefaultNotes
show_titleShow titlebooleantrue
show_descriptionShow descriptionbooleantrue
show_countShow product countbooleantrue
show_sortShow sort optionsbooleantrue
show_filtersShow filtersbooleantrue
columnsColumnsrange42 to 5
card_styleCard styleselectplainone of plain, bordered, shadow
image_ratioImage shapeselect1/1one of 1/1, 4/5, 3/4
show_priceShow pricebooleantrue
show_badgeShow sale and sold out badgebooleantrue
empty_imageEmpty state imageimage
empty_titleEmpty state titletext&#123;"ar":"مفيش منتجات هنا لسه","en":"No products here yet"&#125;set per language
empty_textEmpty state texttextarea&#123;"ar":"جرب قسم تاني أو ارجع للمتجر.","en":"Try another collection or go back to the shop."&#125;set per language
empty_button_labelEmpty state buttontext&#123;"ar":"كل المنتجات","en":"All products"&#125;set per language
empty_button_linkEmpty state button linklink/products
empty_button_styleEmpty state button styleselectsolidone of solid, outline, ghost
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
products_labelproducts
sort_bySort by
filtersFilters

How it works

  • This code uses the tags hk-section, hk-heading, hk-rich-text, hk-pagination, hk-image, hk-sections.
  • collection.products is the page of products to show, drawn with {% for p in collection.products limit: 48 %} and the same product-card snippet as the grid.
  • collection.sort_options and collection.filters are lists the platform fills in; the section loops over them to print the links.
  • hk-pagination prints the page links from the paginate value the platform provides.
  • hk-heading, hk-rich-text and hk-image print the collection title, description and banner.
  • Labels such as Sort by and Filters come from t('sort_by') and t('filters'), so they translate with the locale files.

Next steps