تخطَّ إلى المحتوى

البناء باستخدام واجهة

كيف يُبنى سياق القالب

غير مترجمة بعدهذه الصفحة متوفرة بالإنجليزية فقط حتى الآن، وتُعرض أدناه بالإنجليزية بدل حجبها.

Your template cannot fetch anything. Everything it can see was assembled by the route before rendering began. This page explains what that means in practice.

The rule

The context is fully materialised before the template runs. A template cannot trigger a query, an API call or any other I/O.

There is no lazy loading, no product.reviews.load(), no {% query %} tag. If a value is not in the context, it is not available on that page.

Why it works this way

Three separate problems are solved by the same decision:

Tenancy. A template can only ever see rows the route fetched for the current store. There is no expression that could reach another merchant's data, because there is no expression that reaches data at all.

Predictable performance. Lazy loading inside a loop is how storefronts become slow — one query per product, forty products, forty queries. Here a page issues a fixed, countable number of queries decided by the route, and that number does not change with what your template happens to render.

Containment. A template cannot obtain a database handle or a request object, because the context contains only plain data: strings, numbers, booleans, lists and maps. Nothing in it has methods to call.

The cost is real: a route has to know in advance what data it might need. That is why the per-template pages in the Templates Library enumerate exactly what each one provides, and why those lists are a contract rather than a guideline.

What every page has today

NameFields
storename (in the page's language), name_ar, name_en, slug, currency, country, timezone
pagetemplate, canonical_url, alternates (a list of locale and url)
requestpath, locale, direction, other_locale, other_locale_url
themename, version, asset_base, parent_asset_base (empty unless the theme extends another)
tYour theme's strings in the page's language, from locales/
wajhaReserved: the platform's markup for {% wajha_head %} and {% wajha_body %}

wajha is not for printing: {{ wajha.head }} shows the markup as escaped text. Place it with the tags instead.

name_ar and name_en are empty when the merchant gave no name in that language; name is never empty — it falls back to the other language rather than rendering a blank heading.

request deliberately excludes headers, cookies, the client's address, the raw host and any internal identifier. Every URL in the context is built from the store's own address, never copied from the request. If you need to branch on something, branch on data you were given.

Product images

A product page's product, and every product card (item in a product grid), carry the merchant's photos as plain data:

NameWhat it is
product.imagesEvery photo, in the merchant's order. Empty when the product has none
product.imageThe main photo (the first), or nothing
item.imageA card's main photo, or nothing
image.urlWhere it is served from; print it with the url filter
image.widthThe file's own width and height, for the width and height attributes
image.altThe merchant's description in the page's language, else the product's name
image.variant_idThe variant it shows, or empty for the whole product

Always keep a fallback for a product without a photo, and always write width, height and alt: the first stops the page jumping as photos load, the second is what a screen reader says. The platform puts the main photo in the link preview (og:image) for you.

Image settings

A setting of type image lets the merchant choose a picture they uploaded to their store — a hero's photograph, a banner's, a tile's. Declare one per picture (a section may have several, and so may your global settings), each with a "" default, and a localized text setting beside it for its description:

{
  "settings": [
    { "id": "image", "type": "image", "label": { "ar": "الصورة", "en": "Image" }, "default": "" },
    {
      "id": "image_alt",
      "type": "text",
      "localized": true,
      "label": { "ar": "وصف الصورة", "en": "Image description" },
      "default": { "ar": "", "en": "" }
    }
  ]
}

In a template the setting is an object, or nothing when no picture is chosen or the merchant has since deleted it:

NameWhat it is
urlWhere it is served from; print it with the url filter
widthThe file's own width in pixels — always there when the picture is
heightThe file's own height in pixels — always there when the picture is
{% if section.settings.image %}
  <img src="{{ section.settings.image.url|url }}" width="{{ section.settings.image.width }}"
       height="{{ section.settings.image.height }}" alt="{{ section.settings.image_alt }}"
       loading="lazy" decoding="async">
{% endif %}

Use fetchpriority="high" instead of loading="lazy" for a picture at the top of the page. An empty description makes the picture decorative (alt=""). The platform serves the file as uploaded — there are no resized versions and no srcset yet — so crop with CSS (object-fit: cover and an aspect-ratio) rather than relying on the photo's own shape.

A theme cannot ship a default picture: an image setting's default, and any preset's value for it, must be "", or the theme is refused. If your design needs art when the merchant has chosen nothing, draw it from your own assets in the {% else %} branch.

What is coming

Each of these arrives with the part of the platform that produces it, and this page will list its fields when it does:

NameWhat it will be
settingsYour schema's defaults merged with the merchant's choices
products, productCatalogue data, with every amount pre-formatted
categories, categoryThe category tree, depth-capped
menusheader, footer, mobile
cartLines, totals, item count
customerThe signed-in shopper, or null
sectionsThe page's sections, in the merchant's order

Sections will declare their data

A section that renders products will say so in its schema, and the route will batch every section's needs into one query — so three product sections on a homepage are still one products query, not three:

{
  "type": "featured_products",
  "name": { "en": "Featured products", "ar": "منتجات مختارة" },
  "data": { "source": "products", "limit": 12 },
  "settings": [
    { "id": "heading", "type": "text", "localized": true },
    { "id": "columns", "type": "range", "min": 2, "max": 6, "default": 4 }
  ]
}

The context will have a size budget

Once pages carry catalogue data, a page whose context exceeds the budget will fail with the platform's error page and a logged reason naming the collection that overflowed. It will not be silently truncated — a store quietly missing half its catalogue is a support ticket nobody can diagnose. If you need more than the cap, paginate.

Working with what you have

{% if products %}
  <ul class="grid">
    {% for product in products %}
      {% include 'partials/product-card.jinja' %}
    {% endfor %}
  </ul>
{% else %}
  <p>{{ t.catalogue.empty }}</p>
{% endif %}

Always handle the empty case. A merchant installs your theme on an empty store, and the first thing they see is your homepage with no products in it.