المفاهيم الأساسية
البنية
This page describes how a Wajha theme is put together and what happens when a shopper loads a page.
Theme structure
my-theme/
├── manifest.json name, version, engine compatibility, fonts
├── settings.schema.json what the merchant may change in the Theme Editor
├── templates/
│ ├── layout.jinja the shell every page extends
│ ├── home.jinja
│ ├── product.jinja
│ ├── cart.jinja
│ ├── 404.jinja
│ └── partials/
│ ├── header.jinja
│ └── product-card.jinja
├── assets/
│ ├── theme.css
│ └── theme.js
└── locales/
├── ar.json
└── en.json
Nothing outside templates/ is rendered. assets/ is served under a fingerprinted,
long-cacheable URL; locales/ holds the strings templates read as t.
manifest.json says what the theme is:
{
"code": "my-theme",
"name": { "ar": "ثيمي", "en": "My Theme" },
"version": "1.0.0",
"engine": 1,
"extends": "wajha-base",
"fonts": { "heading": "amiri", "body": "readex-pro" }
}
name is a string, or the name in each language as above, both filled; the Theme Editor and
the theme list show the merchant's language. We never translate it. code is what a store
records, so it never changes once a store may have chosen your theme; a new name is a new
name, not a new code. extends is optional; see
Extending another theme. fonts names the faces the theme is
designed in; see Fonts.
The settings schema
settings.schema.json declares what a merchant may change: global settings, the sections a
merchant may place, and presets (the layout a store starts with). Two optional fields shape
how the Theme Editor presents them:
{
"groups": [{ "id": "navigation", "label": { "ar": "التنقّل", "en": "Navigation" } }],
"settings": [
{
"id": "nav_4_label",
"type": "text",
"localized": true,
"group": "navigation",
"label": { "ar": "نص الرابط 4", "en": "Link 4 text" },
"default": { "ar": "", "en": "" },
"placeholder": { "ar": "دليل المقاسات", "en": "Size guide" }
}
]
}
placeholderis an example shown in the empty field, and never a value: it is not a default, it is never saved, and the shop never renders it. Use it to suggest copy that makes a promise — a delivery time, a returns window, a size guide — so a merchant who keeps it has chosen to, and a new store publishes nothing it did not write. Onlytext,textareaandurlsettings take one:{ "ar", "en" }(both filled) for alocalizedsetting, a string otherwise.groupfiles a global setting under one ofgroups, which the editor shows as collapsible panels in the order you declare them. Declare each group's label once, ingroups. Section settings take no group: a section is already its own panel.
An unknown group, a group on a section's setting, or a placeholder of the wrong shape refuses the theme when it loads, naming the setting.
The kinds of setting are text, textarea, url, color, range, toggle, select,
image and font — typed inputs only, never markup. A font setting chooses one of the
store's two faces; see Fonts.
Extending another theme
A theme can name another in extends and ship only what makes it different: its layout,
header, footer, home page, product cards, product page, sections and styles. Every page it
does not ship — cart, checkout, account, order, payment, 404 — comes from the theme it
extends, drawn inside your layout with your strings and the merchant's saved
settings for your theme.
-
One level. The theme you extend is another theme in the catalogue — today, one of the platform's own, such as
wajha-base— and it extends nothing itself. Naming an unknown theme, your own, or one that extends another, is refused when your theme loads. -
Your file wins, everywhere. A template at the same path as one of the parent's replaces it, including inside the parent's own templates: an inherited
cart.jinjathat says{% extends "layout.jinja" %}gets your layout, and an inherited section that includespartials/product-card.jinjagets your card. Your layout must therefore keep the blocks the parent's pages fill —titleandcontentinwajha-base. -
Strings are merged key by key, yours winning. You may add and replace strings, not turn a group of strings into one string or the reverse. The Arabic and English files are checked for the same keys after merging. Both files are optional when you add no strings.
-
Settings and sections are merged with the parent's: a global setting by
id, a section bytype— yours replaces the parent's in place, or is added after them — and a preset by page. A setting you redeclare keeps its kind (typeandlocalized); you may change its label, default or options. Two extra keys in yoursettings.schema.jsondecline what you do not offer:{ "exclude_sections": ["hero"], "exclude_settings": ["announcement", "footer_tagline"] }A declined section disappears from the Theme Editor and its template from your theme. A declined setting must not be read by any template your theme still uses — inherited ones included — or the theme is refused, naming the template.
-
Assets.
theme.asset_baseserves yourassets/merged over the parent's: your file shadows the parent's at the same path, and every other parent file is there too.theme.parent_asset_baseserves the parent's own files only, so you can link the parent's stylesheet even when yours has the same name. Link it first, then yours, so inherited pages stay styled and your rules win:<link rel="stylesheet" href="{{ theme.parent_asset_base }}/theme.css"> <link rel="stylesheet" href="{{ theme.asset_base }}/theme.css">Both URLs change whenever the parent's files change, so they stay safe to cache forever.
Everything a theme is checked for when it loads is checked on the merged result. Groups merge by
id like settings, so redeclaring a parent's group relabels it.
What wajha-base gives every theme that extends it
wajha-base (shown to merchants as Sarooj) declares a settings vocabulary its children
inherit, so merchants find the same choices in every theme and their content follows them when
they switch:
| Setting | What it is |
|---|---|
nav_1_label … nav_4_label, nav_1_url … | Four menu links; render one only when both its label and its URL are set |
contact_label, contact_url | The store's contact link (tel: and https://wa.me/… work); "ask us" copy needs it |
show_dock | The shared mobile dock, off by default |
announcement, announcement_link | The bar above the header |
accent_color, button_shape, corner_style | Style |
heading_font, body_font | The shop's two faces (Fonts) |
footer_tagline, show_powered_by | The footer |
Include its partials rather than rewriting them: partials/nav-links.jinja (the menu links as
<li>s), partials/contact-link.jinja, partials/social-name.jinja (a store.social link's
name in words), partials/link-href.jinja (a link setting as an href that keeps the page's
language) and partials/dock.jinja — Home, Shop, Account and Cart along the bottom of a phone,
never on checkout, payment, sign-in or account pages. Restyle the dock by setting
--dock-surface, --dock-ink, --dock-current-surface and --dock-current-ink on .dock; go
without it by shipping an empty partials/dock.jinja and adding show_dock to
exclude_settings.
The rules every theme in the family keeps:
- Link
{{ theme.parent_asset_base }}/theme.cssbefore your own stylesheet; keep thetitleandcontentblocks and<main id="main">. - Link the platform's pages with
{{ routes.home }},{{ routes.cart }}and the rest, never a literal path, so the shopper's language survives the click. - Exactly one
<h1>per page whatever sections the merchant places — on the home page, inhome.jinja, not in a section — and nostyleattribute anywhere. - Money only through
.display, inside<bdi>. Merchant colours only as surfaces, with their-inkon top. Arangevalue through|integerwhen you compare or loop on it. fetchpriority="high"only on the first hero picture. Motion only inside@media (prefers-reduced-motion: no-preference).- Keep the base section types —
hero,featured_products,category_list,trust_bar,rich_text,promo_banner— for sections that do the same job, so a merchant's content follows them into your theme. - Default copy promises nothing a merchant may not keep; put promises in placeholders.
The render pipeline
A request to a merchant's domain goes through five stages:
| Stage | What happens |
|---|---|
| Resolve | The host names a store. An unknown host is a 404 — not an error page naming the platform. |
| Select | We find the theme version that store has published. |
| Build context | The route assembles its data: the store, the page, products, cart, settings. |
| Render | Your template runs against that data and writes HTML. |
| Cache | The response is cached at the edge, keyed by host, path, language and currency. |
The context is built before your template runs
This is the single most important property of the engine, and the one that differs most from client-side theming. Your template cannot fetch. It cannot query. Every value it can reach was placed there by the route before rendering started.
Three things follow, and all three are why it works this way:
- Tenancy. A template can only see rows the route fetched for this store. There is no way to address another merchant's data, because there is no way to address anything.
- Predictable performance. No lazy loading means no accidental query in a loop. Every page issues a fixed, countable number of queries.
- Containment. A template cannot reach a database handle, because no database handle is in the context.
Themes, versions and settings
Three separate things, deliberately:
- A theme is your product — a name, a code, an author.
- A version is an immutable snapshot of its files. Publishing points a store at one.
- Settings are the merchant's own data, stored against their store, referencing your schema.
Because settings live outside your files, a merchant can update from 2.0 to 2.1 and keep every choice they made. Because versions are immutable, a bad release can be rolled back by pointing the store at the previous one — no redeploy, no file restore.
Templates and routes
| Route | Template | Served |
|---|---|---|
/ | home.jinja | yes |
| anything unmatched | 404.jinja | yes |
/products | products.jinja | with product data |
/products/{slug} | product.jinja | with product data |
/categories/{slug} | category.jinja | with product data |
/pages/{slug} | page.jinja | with page content |
/search | search.jinja | with search |
/cart | cart.jinja | with the cart |
Any of these you do not implement falls back to the platform default — the whole page, in the default theme's layout. A theme that extends another gets the parent's template instead, inside its own layout.
Merchant colours
Pages are served with style-src 'self' and no inline styles, so a template cannot write a
merchant's colour into a style attribute. The platform serves it instead: {% wajha_head %}
links a per-store stylesheet that sets CSS custom properties on :root, built from the
store's brand and from your schema's global color and range settings:
| Property | Value |
|---|---|
--wajha-brand-primary, --wajha-brand-secondary | the store's brand colours |
--wajha-setting-<id> | a color setting, or a range setting as a number; underscores in the id become hyphens |
…-ink | #ffffff or #0d0f0d, whichever is more readable on the colour |
…-hover, …-soft | the colour nudged toward its ink, and a pale tint of it |
Read them with your own values as fallbacks, so the theme looks right with no stylesheet:
.button--accent {
background: var(--wajha-setting-accent-color, #c5f04a);
color: var(--wajha-setting-accent-color-ink, #0d0f0d);
}
Use a merchant's colour as a surface with its -ink on top, never as text on your own
background: you cannot know it will be readable. A select or toggle changes markup
instead — put it on an element (<body data-buttons="{{ settings.button_shape }}">) and key
your CSS off the attribute.
Fonts
A merchant chooses their shop's heading font and body font in the Theme Editor, from the platform's catalogue of faces that draw both Arabic and Latin. Your theme's own pairing is the default. The platform loads the faces, not your theme:
-
Name your pairing in
manifest.json:"fonts": { "heading": "<code>", "body": "<code>" }, and optionally"extras": ["ibm-plex-mono"]for at most two faces you need for one purpose (a monospace for product codes) that no merchant picks. A code the catalogue lacks, or a display face named forbody, refuses the theme. A theme that extends another and names no fonts has its parent's. -
Never link a font service.
{% wajha_head %}writes one Google Fonts stylesheet, withdisplay=swap, for exactly the faces a page uses — the merchant's choice or your default for headings and body, plus your extras. -
Read the two faces from CSS. The per-store stylesheet sets
--wajha-font-headingand--wajha-font-bodyon:root— the family and its fallback stack — always. Use them with your own stack as the fallback, so the theme looks right with no stylesheet::root { --font: var(--wajha-font-body, 'Readex Pro', system-ui, sans-serif); --display: var(--wajha-font-heading, 'Amiri', 'Times New Roman', serif); } body { font-family: var(--font); } h1, h2 { font-family: var(--display); }Name a family literally only inside those fallbacks, or for one of your extras.
-
Let a heading reflow. A merchant may pick a much wider face than yours (Lalezar) or a narrower one. Let titles, wordmarks and prices wrap rather than clip them with a fixed width or
white-space: nowrap.
The settings themselves are font settings, which wajha-base declares for you as
heading_font and body_font:
{
"id": "heading_font",
"type": "font",
"role": "heading",
"label": { "ar": "خط العناوين", "en": "Heading font" },
"group": "style",
"default": ""
}
The value is a catalogue code, or "" for your own face. role is required — heading or
body — and limits the faces offered: a display face (Lalezar, Reem Kufi, Baloo Bhaijaan 2, Aref
Ruqaa) is for headings only. A font setting is global, one per role, and its default is "".
| Code | Family | For |
|---|---|---|
ibm-plex-sans-arabic, readex-pro | IBM Plex Sans Arabic, Readex Pro | headings, body |
noto-sans-arabic, noto-kufi-arabic | Noto Sans Arabic, Noto Kufi Arabic | headings, body |
cairo, tajawal, almarai | Cairo, Tajawal, Almarai | headings, body |
rubik, changa, el-messiri | Rubik, Changa, El Messiri | headings, body |
noto-naskh-arabic, amiri, markazi-text | Noto Naskh Arabic, Amiri, Markazi Text | headings, body |
reem-kufi, baloo-bhaijaan-2 | Reem Kufi, Baloo Bhaijaan 2 | headings |
lalezar, aref-ruqaa | Lalezar, Aref Ruqaa | headings |
ibm-plex-mono | IBM Plex Mono | a theme's extras |
Where the boundary sits
Your theme owns presentation. It does not own business rules: prices, stock, shipping bands and tax are computed before rendering and arrive as finished values. You cannot recompute a total in a template, and should not try — see Money, Dates & Numerals for why that restriction prevents an entire class of currency bug.