Managing pages and designs (step-by-step)¶
Who this is for: anyone who needs to change how the websites look or behave — no coding required for the common cases. Since the data-driven engine (P1) shipped, pages and designs are configuration, not worker code.
The Cloudflare Worker is now a generic engine. It reads "page descriptors" (rows in the
page_typestable, served inside the API's/settings) and the template HTML/CSS, then renders. You change the data; the live site changes — no worker deploy for the cases below.
Read the box that matches your task. Each is a numbered checklist. Copy-paste commands assume you run them from the workspace root.
Glossary (read once)¶
- Template — a named shell a site uses (e.g.
celebrity-v1). Selected via the site'stemplate_stylespairing (site_settings.template_style_id), not a baresites.template_idcolumn. - Template block / shell — HTML for page slots, served from the versioned
S3 shell (
templates/<slug>/<version>/shell.html) and hydrated intosite_settings.templatesat resolve time. - Page descriptor — a row in
page_typesthat says: this URL pattern → use these content slots, fetch this data, cache for this long. This replaces the old hardcoded routing in the worker. - style — a named skin in the DB-backed styles registry. CSS bytes live
in S3 (
styles/<slug>/<version>.css). A site picks a skin through itstemplate_style_idpairing;/settingssurfacesactive_style: { id, slug, version }. The worker links/_assets/styles/style/<slug>/<version>.css. See Styles and CSS. - css_version — legacy per-template CSS path (used only when a site has no
active_style). Prefer the styles registry. - variant — lets one page type have more than one layout (e.g. a
defaultarticle and alisticlearticle) on the same site.
The element_type names that exist: homepage, article, category, author,
contact_us, about, privacy_policy, terms_of_use, do_not_sell, 404
(page slots) and layout, header, footer, sidebar, article_card,
breadcrumb, pagination, author_card (components).
TASK A — Change the look of a site (new CSS / redesign)¶
You are changing colors, fonts, spacing — the stylesheet. CSS lives as a
versioned S3 object in the cms-templates bucket (registry row points at
styles/<slug>/<version>.css). The worker fetches the bytes from cms-api and
edge-caches them by version.
- Edit the local mirror under
cms-cf-worker/templates/styles/<slug>/, then upload a new version via cms-api (or change the site'stemplate_style_idto another pairing):curl -X POST "https://cms-api-stg.skyneto.com/admin/v1/styles/${STYLE_ID}/file" \ -H "Authorization: Bearer $TOKEN" \ -F "file=@cms-cf-worker/templates/styles/<slug>/<file>.css" - Purge the site cache so already-rendered pages re-render with the new
<link>(send a normal browserUser-Agent— bare clients can get CF 1010):curl -X POST https://dev.fashionradar.net/__cms/purge \ -H "Authorization: Bearer $ADMIN_PURGE_SECRET" \ -H "content-type: application/json" \ -H "User-Agent: Mozilla/5.0" \ -d '{"host": "dev.fashionradar.net", "site": true}' - For a change that must be live everywhere immediately, a purge alone is
not enough — follow the full three-step recipe (purge, redeploy the site
worker to clear the isolate memMap, then
purge_everythingthe CF zone) in Caching → the propagation recipe. Verify with the plain URL, not a?queryvariant (a query bypasses the edge cache and hides staleness). - What success looks like: view-source on the plain URL of any page shows
the new stylesheet link (e.g.
<link rel="stylesheet" href="/_assets/styles/style/<slug>/<version>.css">), and that file returns your new CSS.
Why a new version instead of overwriting? The CSS URL is cached forever (immutable) and the worker edge-caches the cms-api fetch by version. A new version is a new URL, so browsers and the edge pick it up instantly and old cached pages keep working during the switch.
No worker code change is needed for the CSS itself. (A redeploy is only
part of step 3, to clear warm isolates for site-settings changes.) After upload,
re-sync the git mirror per templates/README.md. Also see
Responsive images for the shared fluid CSS baseline.
TASK B — Change the HTML of a page section (e.g. the article layout)¶
You are changing the markup/structure of a slot (header, article body wrapper, card, footer, …).
- Find the block for the element_type you want (e.g.
article) on the site's template, and edit itshtml_content. Use the admin API / DB:The markup is a small Handlebars-style template. Keep the placeholders the builder expects, e.g.UPDATE template_blocks SET html_content = '<main> ... your new markup ... </main>' WHERE template_id = (SELECT id FROM templates WHERE slug = 'celebrity-v1') AND element_type = 'article';<div data-render="content_blocks"></div>,<div data-grid="related_articles"></div>,<div id="sidebar-slot"></div>. - To change just ONE site (not every site on the template), set a site
override instead of editing the shared block:
-- via admin API: PUT /admin/v1/sites/{site_id}/block-overrides -- { "element_type": "article", "html_content": "<main>…</main>" } - Purge the cache (see Task A step 2).
- Success: the page renders your new markup.
No worker deploy.
TASK C — Add a brand-new page type (URL pattern)¶
Example: add a /tag/{slug} listing page that shows articles for a tag.
First ask: does it just fetch a list (or a single item) and drop it into slots, like category/author/homepage already do?
-
Yes → it's pure configuration (no code). Add a
page_typesrow:Field meanings:INSERT INTO page_types (template_id, type, variant, routes, layout, ttl, sources, grids, seo, position, is_active) SELECT id, 'tag', 'default', '["/tag/{slug}"]', '["category"]', 300, '[{"bind":"list","call":"lists","params":{"kind":"category","category_slug":"{slug}"}}]', '{"articles":"list"}', '{"from":"site"}', 45, 1 FROM templates WHERE slug = 'celebrity-v1';routes= URL patterns ({x}captures a param);layout= which content slot(s) to render (here it reuses thecategoryblock);sources= what to fetch and what to call it;grids= putlist's items into thedata-grid="articles"placeholder;ttl= cache seconds;seo.from= where the title/description come from (sitedefaults). Then purge the cache. Success:/tag/anythingrenders the list. No deploy. -
No — it needs custom logic (special data shaping, an unusual layout the generic path can't express) → this needs a small builder in the worker (code + one deploy). See
AGENTS.md("When code IS required").
TASK D — Add a layout VARIANT for an existing page type¶
Example: some articles should use a "listicle" layout, others the normal one, on the same site.
- Add a second
page_typesrow for the sametypewith a differentvariant:INSERT INTO page_types (template_id, type, variant, routes, layout, ttl, builder, seo, position, is_active) SELECT id, 'article', 'listicle', '["/{category}/{slug}"]', '["article"]', 1800, 'article', '{"from":"page"}', 40, 1 FROM templates WHERE slug = 'celebrity-v1'; - Make sure a
listiclearticle block exists (Task B) if the markup differs. - The variant is chosen per content item (e.g. from the content's
settings.layoutfield). Set that on the articles that should use it. - Purge the cache. Success: flagged articles render the listicle layout; the rest stay default.
TASK E — Change a static page (Contact, About, Privacy, …)¶
Prefer the site setting keys (AISD-227): privacy_policy_html,
do_not_sell_html, terms_of_use_html, about_html, contact_us_html.
Patch via admin PATCH /admin/v1/sites/{id}/settings (per-site override) or
edit the site_id=-1 global defaults. The worker prefers the merged setting
over the shell template block; editing only template_blocks.html_content has
no effect once the setting is non-empty. Purge cache after change. No deploy.
TASK F — Sidebar position / visibility (layout_customization)¶
Site-wide sidebar behavior — its position (left / right / none) and
whether the editor's-picks, categories, and tags widgets show —
is config, not code, via site_settings.layout_customization (served by
cms-api, AISD-190; consumed by cms-cf-worker, AISD-191).
The admin write schema (422 on unknown keys) is documented in cms-api
docs/public-v2-api.md under layout_customization. This section is the
operator runbook for applying and verifying it.
Vocabulary (v1, flat / site-wide)¶
{
"sidebar": {
"position": "left" | "right" | "none",
"editors_picks": { "visible": true },
"categories": { "visible": true },
"tags": { "visible": true }
}
}
All fields are optional. Admin write rejects unknown keys with HTTP 422.
Defaults (blob absent / null / {} / malformed)¶
| Concern | Effective default |
|---|---|
| Position | Template/CSS default (sidebar on the right). No sidebar-pos-* body class / data-sidebar-position. |
| Editors' picks | Shown; worker fetches picks as today (show_editors_picks defaults true). |
| Categories / tags | Follow the sidebar template-block toggles show_categories / show_tags. |
Malformed blobs (wrong type) are treated like absent — no throw, no customization.
Precedence / merge¶
| Config field | When present | When absent |
|---|---|---|
sidebar.position |
Wins (drives omit / body hooks) | Default layout (no body hook) |
sidebar.categories.visible |
Wins over block show_categories |
Block show_categories |
sidebar.tags.visible |
Wins over block show_tags |
Block show_tags |
sidebar.editors_picks.visible |
Wins (only site-wide pick hide) | Picks fetch + widget as today |
Resolution is centralized in getSidebarSettings (src/pages/_shared.ts);
page builders and the generic engine do not read layout_customization
directly.
Required template hooks¶
| Hook | Where | Purpose |
|---|---|---|
<div id="sidebar-slot"></div> |
Page body templates (homepage, article, category, author, …) | Fill / remove target for the sidebar |
Class token editors-picks on the picks widget wrapper |
templates.sidebar |
Removed when editors_picks.visible === false |
Class token categories-widget on the categories widget wrapper |
templates.sidebar |
Removed when categories.visible === false |
data-render="tags" |
Article template | Omitted when tags.visible === false |
<body class="sidebar-pos-left\|right" data-sidebar-position="…"> |
Emitted by renderLayout |
Positions the sidebar left or right |
data-slot="below_title" |
Article shell, after .article-meta |
Empty ~100px ad slot (AISD-233; not filled by worker) |
data-slot="after_section" |
Article shell, after data-render="content_blocks" |
Sentinel for ~300px after-section ads; per-section cloning is injection-team / follow-up |
data-slot="custom_scripts_header" |
Shell scripts_header → spliced into <head> by renderLayout |
Empty head script mount for external scripts team |
data-slot="custom_scripts_body" |
Shell scripts_body → spliced before page runtimes by renderLayout |
Empty body script mount for external scripts team |
A missing #sidebar-slot or renamed widget classes → strip / position: "none"
may silently no-op; the worker does not error.
Script / ad placeholders (AISD-233)¶
Empty hooks for the scripts team. Full contract, layout splice behavior, upload steps, and out-of-scope notes: Script and ad placeholders.
Summary: renderLayout splices empty scripts_header / scripts_body into
<head> / before page runtimes; article shells also expose below_title and
after_section. The worker does not fill slots or read cms_scripts /
scripts_split_config yet.
<div data-slot="below_title"></div>
<div data-slot="after_section"></div>
<div data-slot="custom_scripts_header"></div>
<div data-slot="custom_scripts_body"></div>
Minimal sidebar shell:
<aside class="sidebar">
<div class="editors-picks sidebar-widget">
<h3 class="widget-title">Editor's Picks</h3>
<div class="trending-list">…</div>
</div>
<div class="categories-widget sidebar-widget">
<h3 class="widget-title">Categories</h3>
<div class="categories-list">…</div>
</div>
</aside>
Apply / verify¶
- Set it via the admin API:
Optional: resolve stage hosts with
curl -X PATCH https://cms-api.example/admin/v1/sites/$SITE_ID/settings \ -H "Authorization: Bearer $ADMIN_TOKEN" -H "content-type: application/json" \ -d '{"layout_customization": {"sidebar": {"position": "left", "categories": {"visible": false}}}}'hq/.venv/bin/python -m hq.deploy check cms-api --env stageandhq/.venv/bin/python -m hq.deploy check cms-cf-worker --env stage. - Purge the cache (Task A step 2 — same
/__cms/purgepath as any other settings/block edit). For a change that must be visible everywhere immediately, use the full propagation recipe. - What success looks like (view-source on the plain URL):
position: "none"— noid="sidebar-slot"in the HTML (omitted, not CSS-hidden).position: "left"/"right"—<body>carriesdata-sidebar-position="left|right"and classsidebar-pos-left|right; the sidebar appears on that side.editors_picks.visible: false— no editors' picks widget; worker skips the picks fetch.categories.visible: false/tags.visible: false— nocategories-widget/ nodata-render="tags"slot content.- Clear with
{"layout_customization": null}, purge again, confirm the prior sidebar returns.
No worker deploy for changing the values — only the worker code that interprets them (AISD-191) required one.
When something DOES need a worker deploy¶
Only these need code + npm run deploy:site-stage (then prod after sign-off):
- A genuinely new builder (custom rendering logic) — see
AGENTS.md. - Changing the engine itself (routing rules, caching, the Handlebars renderer).
- New global behavior (headers, security, redirects).
Everything else on this page is configuration.
Quick reference¶
| I want to… | Where | Deploy? |
|---|---|---|
| Change colors/fonts | style/CSS in cms-api + bump version | No |
| Change a section's HTML | template_blocks.html_content (or site override) |
No |
| Add a list/detail page | new page_types row |
No |
| Add a layout variant | new page_types row (same type, new variant) |
No |
| Edit a static page | site_settings.*_html (fallback: shell template_blocks) |
No |
| Sidebar position / hide picks/categories/tags | site_settings.layout_customization |
No |
| Custom rendering logic | new builder in src/engine |
Yes |
After any data change, purge the cache (Task A step 2) or wait for the TTL. For a change that must be visible everywhere immediately, follow the full propagation recipe and verify with the plain URL.