Frontend & Templates¶
Auto-generated from knowledge base TOML files by
docs_gen.py. Do not edit manually; rundazzle docs generateto regenerate.
The Dazzle frontend uses the typed Fragment substrate (frozen-dataclass HTML primitives) with HTMX for declarative server interactions. Surfaces declare render: fragment in DSL; the runtime emits HTML from a primitive tree, escaped at the boundary by default. No Jinja2 since #1042 / v0.67.92 (ADR-0023). This page covers the rendering architecture, fragment contracts, out-of-band swaps, sitespec configuration, copy management, section types, and static asset serving.
Htmx¶
Declarative HTTP interaction layer for Dazzle-generated frontends. All interactions expressed via HTML attributes (hx-get, hx-post, hx-target, hx-swap, hx-trigger). Server renders HTML fragments; HTMX swaps them into the DOM.
Syntax¶
<element
hx-{verb}="/endpoint" <!-- get, post, put, delete -->
hx-target="#target-id"
hx-swap="innerHTML" <!-- innerHTML, outerHTML, beforeend, etc. -->
hx-trigger="click" <!-- click, keyup, change, load, etc. -->
hx-indicator="#spinner">
Example¶
<!-- Debounced search -->
<input type="text"
hx-get="/_dazzle/search"
hx-target="#results"
hx-trigger="keyup changed delay:400ms"
hx-indicator="#search-spinner">
<!-- Row click navigation -->
<tr hx-get="/contacts/{{ id }}"
hx-target="body"
hx-push-url="true">
<!-- Inline delete with confirmation -->
<button hx-delete="/_dazzle/tasks/{{ id }}"
hx-target="closest tr"
hx-swap="outerHTML"
hx-confirm="Delete this task?">
Related: Templates, Fragment Contract, Oob Swap
Templates¶
Typed Fragment substrate (frozen-dataclass HTML primitive tree → emitted HTML via dazzle.render.html.esc). Surfaces declare render: fragment in DSL; the runtime emits HTML from a primitive tree, escaped at the boundary by default. The few remaining template paths use either f-strings + dazzle.render.html.esc (Pattern A: framework writes HTML) or string.Template (Pattern B: framework executes user-authored templates). See ADR-0023. Post-#1042 (v0.67.92) Jinja2 is no longer a dependency.
Syntax¶
# DSL opt-in:
surface task_list "Tasks":
uses entity Task
mode: list
render: fragment # <-- typed Fragment substrate
# Runtime emission path:
AppSpec (IR)
→ converters (surface_converter, workspace_converter)
→ typed Fragment tree (frozen dataclasses, HTML5 element/attribute allowlist)
→ HTML + hx-* attributes (escaped by default)
Related: Htmx, Fragment Contract, Surface
Fragment Contract¶
A fragment's formal interface specifying required/optional params, events it emits, events it listens to, and swap targets. Enables LLM agents to compose fragments without reading implementation.
Syntax¶
fragment: <name>
template: fragments/<name>.html
params:
required: [field.name, field.label, endpoint]
optional: [placeholder, debounce_ms]
emits: [itemSelected, formSaved]
listens: [searchCleared]
swap_targets: ["#{{ field.name }}-results"]
oob_targets: ["#field-{{ autofill_target }}"]
Example¶
# Discovery before modification
mcp__dazzle__dsl(operation="list_fragments")
# Returns structured contracts:
{
"search_select": {
"params": ["field.name", "field.source.endpoint", ...],
"emits": ["itemSelected"],
"listens": [],
"description": "Debounced search with autofill"
}
}
Oob Swap¶
Out-of-band swap pattern (hx-swap-oob) for updating multiple DOM elements from a single server response. Used for autofill: selecting a search result populates multiple related form fields.
Syntax¶
<!-- Server response includes multiple elements -->
<!-- Primary swap (goes to hx-target) -->
<div id="search-selected">Selected: Acme Ltd</div>
<!-- OOB swaps (go to their own ids) -->
<input id="field-company_number" value="12345678"
hx-swap-oob="outerHTML" readonly />
<input id="field-status" value="active"
hx-swap-oob="outerHTML" readonly />
Example¶
# Python endpoint returning OOB response
from dazzle.http.runtime.htmx import render_oob_fields
@router.get("/select/{id}")
async def select_company(id: str):
company = await get_company(id)
return render_oob_fields(
primary=f"Selected: {company.name}",
autofill={
"company_number": company.number,
"company_status": company.status,
}
)
Related: Htmx, Fragment Contract, Search Select
Sitespec¶
Site configuration file (sitespec.yaml) defining brand, navigation, page structure, legal pages, auth pages, and integrations. Structural configuration for the marketing/public site shell. Pages use typed sections (hero, features, cta, markdown, comparison, card_grid, trust_bar, etc.) and can be hybrid — mixing structured sections with markdown content blocks. See 'section_types' for all available section types.
Syntax¶
# site/sitespec.yaml
version: "1.0"
brand:
product_name: "FreshMeals"
tagline: "Chef-quality meals delivered"
support_email: "support@freshmeals.com"
layout:
nav:
public:
- label: "Features"
href: "/features"
footer:
columns:
- title: "Product"
links: [...]
pages:
- route: "/"
type: landing
sections:
- type: hero
headline: "Chef-quality meals"
- type: markdown # Inline markdown section
source:
path: "pages/our-story.md"
format: md
- type: comparison # Structured comparison table
headline: "How we compare"
columns:
- label: "Us"
highlighted: true
- label: "Competitor"
items:
- feature: "Delivery"
cells: ["Same day", "3-5 days"]
- type: card_grid
headline: "Our plans"
items:
- title: "Starter"
body: "For individuals"
icon: "user"
cta:
label: "Choose"
href: "/signup?plan=starter"
- type: trust_bar
items:
- text: "SOC 2 Certified"
icon: "shield-check"
- text: "99.9% Uptime"
- type: cta
headline: "Ready to eat well?"
primary_cta:
label: "Start Free Trial"
href: "/signup"
Example¶
# Hybrid page: structured sections + markdown content
pages:
- route: "/about"
type: landing
title: "About Us"
sections:
- type: hero
headline: "About Our Company"
subhead: "Building the future of food delivery"
- type: markdown
source:
path: "pages/about-story.md"
format: md
- type: split_content
headline: "Built for teams"
body: "Collaborate in real time."
media:
kind: image
src: "/img/team.png"
alt: "Team collaboration"
alignment: right
- type: value_highlight
headline: "10x faster deliveries"
subhead: "Ship with confidence"
body: "Our platform reduces delivery time by 90%."
primary_cta:
label: "Try Free"
href: "/signup"
- type: cta
headline: "Join us today"
primary_cta:
label: "Sign Up"
href: "/signup"
Related: Copy Md, Site Coherence, Section Types, Hybrid Pages
Copy Md¶
Founder-friendly markdown file for PROSE marketing content. Best for: hero headlines, feature descriptions, testimonials, FAQ text. NOT for structured data like pricing tiers — those belong in sitespec.yaml. Supports :::type directive fences to create typed sections inline (see 'directive_syntax').
Syntax¶
# site/content/copy.md
# Hero
**Your Headline Here**
Subheadline text explaining the value proposition.
[Get Started](/signup) | [Learn More](/features)
---
# Features
## Fast Performance
Description of the speed benefit. [icon: bolt]
## Easy to Use
Description of the UX benefit. [icon: sparkles]
---
# Testimonials
> "This transformed our workflow!"
> — Jane Smith, CEO at Acme Inc
---
# FAQ
## What is this product?
Clear answer explaining the product.
## How do I get started?
Step by step instructions.
Example¶
# Hero
**Run your business, not your admin**
Automate repetitive tasks and focus on growth.
[Start Free Trial](/signup)
---
# Features
## Automated Workflows
Set up once, run forever. No coding required. [icon: bolt]
## Real-time Analytics
See what matters, when it matters. [icon: chart]
Related: Sitespec, Site Coherence, Directive Syntax, Section Types
Section Types¶
All available section types for sitespec.yaml page sections. Each section has a 'type' field and type-specific fields on SectionSpec. Sections are rendered client-side by the site_renderer.py JS engine. IR models are in dazzle.core.ir.sitespec.
Syntax¶
# Available section types and their key fields:
# All sections support: id (optional anchor ID for deep links)
# hero — Main landing section
- type: hero
id: "hero" # optional: explicit anchor ID
headline: "..."
subhead: "..."
body: "..."
primary_cta: {label: "...", href: "..."}
secondary_cta: {label: "...", href: "..."}
media: {kind: image, src: "...", alt: "..."}
# features — Feature grid
- type: features
headline: "..."
items: # list of {title, description, icon}
# testimonials — Customer quotes
- type: testimonials
headline: "..."
items: # list of {quote, name, role, attribution}
# pricing — Pricing tiers
- type: pricing
headline: "..."
items: # list of {name, price, period, features, cta}
# faq — Q&A accordion
- type: faq
headline: "..."
items: # list of {question, answer}
# cta — Call-to-action block
- type: cta
headline: "..."
subhead: "..."
primary_cta: {label: "...", href: "..."}
# markdown — Embedded markdown content (hybrid pages)
- type: markdown
source:
path: "pages/about.md" # relative to site/content/
format: md # md or html
# comparison — Feature comparison table
- type: comparison
headline: "..."
columns: # list of ComparisonColumn
- label: "Us"
highlighted: true # optional, highlights the column
- label: "Competitor"
items: # list of ComparisonRow
- feature: "Price"
cells: ["$29", "$49"] # one cell per column
# value_highlight — Large typography callout
- type: value_highlight
headline: "10x faster"
subhead: "Ship with confidence"
body: "Detailed explanation..."
primary_cta: {label: "Try Free", href: "/signup"}
# split_content — Text + image side-by-side
- type: split_content
headline: "Built for teams"
body: "Collaborate in real time." # Markdown; or source: {path: why.md}
media: {kind: image, src: "/img/team.png", alt: "Team"}
alignment: right # left (default) or right
# card_grid — Cards with per-card CTAs
- type: card_grid
headline: "Solutions"
items: # list of CardItem
- title: "Feature A"
body: "Description"
icon: "zap" # optional icon name
cta: # optional per-card CTA
label: "Learn More"
href: "/features/a"
# trust_bar — Horizontal signal strip
- type: trust_bar
items: # list of TrustBarItem
- text: "SOC 2 Certified"
icon: "shield-check" # optional icon name
- text: "99.9% Uptime"
Example¶
# A landing page using multiple section types
pages:
- route: "/"
type: landing
title: "Home"
sections:
- type: hero
headline: "Ship Faster"
subhead: "The developer platform"
primary_cta:
label: "Get Started"
href: "/signup"
- type: trust_bar
items:
- text: "SOC 2"
icon: "shield-check"
- text: "GDPR"
- text: "99.9% Uptime"
- type: features
headline: "Why choose us"
items:
- title: "Fast"
description: "Blazing speed"
icon: "bolt"
- title: "Secure"
description: "Enterprise grade"
icon: "shield"
- type: comparison
headline: "How we compare"
columns:
- label: "Us"
highlighted: true
- label: "Competitor A"
- label: "Competitor B"
items:
- feature: "Price"
cells: ["$29/mo", "$49/mo", "$99/mo"]
- feature: "SSO"
cells: ["Included", "Add-on", "Enterprise only"]
- type: card_grid
headline: "Use cases"
items:
- title: "Startups"
body: "Ship your MVP fast"
icon: "rocket"
cta:
label: "Learn more"
href: "/startups"
- type: value_highlight
headline: "10x faster deployments"
body: "Our platform reduces deploy time by 90%."
primary_cta:
label: "See the data"
href: "/benchmarks"
- type: cta
headline: "Ready to start?"
primary_cta:
label: "Sign Up Free"
href: "/signup"
Related: Sitespec, Hybrid Pages, Directive Syntax
Directive Syntax¶
Directive fence syntax for embedding typed sections inside markdown content files. Use :::type to open a directive block and ::: to close it. Prose between fences becomes markdown sections. Reuses copy_parser section parsers for typed blocks. Source: dazzle.core.directive_parser.
Syntax¶
# In any markdown content file (e.g. site/content/pages/about.md)
Prose paragraph — rendered as a markdown section.
:::features
## Fast Performance
Our app is blazingly fast.
## Easy to Use
Simple and intuitive interface.
:::
More prose here — becomes another markdown section.
:::cta
## Ready to start?
[Sign Up Free](/signup)
:::
Example¶
# site/content/pages/landing.md
# This file produces 5 sections when processed:
Welcome to our platform. We make development easy.
:::hero
**Ship Faster Than Ever**
The platform built for modern teams.
[Get Started](/signup)
:::
Our customers love us because we focus on what matters.
:::features
## Automated Deploys
Push to main, we handle the rest.
## Real-time Monitoring
See everything at a glance.
:::
:::faq
## What languages do you support?
All major languages and frameworks.
## Is there a free tier?
Yes, free for up to 3 projects.
:::
Ready to join? Start your free trial today.
Related: Copy Md, Section Types, Hybrid Pages
Hybrid Pages¶
Hybrid pages mix structured sections (hero, cta, comparison) with markdown content blocks in a single page. Use type: markdown sections with a source.path to embed .md files inline alongside structured sections. This enables rich content pages that combine the flexibility of markdown with the structure of typed sections.
Syntax¶
# Hybrid page in sitespec.yaml
pages:
- route: "/about"
type: landing
title: "About Us"
sections:
# Structured section
- type: hero
headline: "About Our Company"
# Markdown content block (loaded from file)
- type: markdown
source:
path: "pages/about-story.md"
format: md
# Another structured section
- type: cta
headline: "Join us"
primary_cta:
label: "Sign Up"
href: "/signup"
Example¶
# Example: /about page mixing 3 section types
# sitespec.yaml:
pages:
- route: "/about"
type: landing
title: "About"
sections:
- type: hero
headline: "Our Story"
subhead: "From garage to global"
- type: markdown
source:
path: "pages/about-founding.md"
- type: split_content
headline: "Our Mission"
body: "Making technology accessible to everyone."
media:
kind: image
src: "/img/mission.png"
alt: "Mission"
alignment: right
- type: markdown
source:
path: "pages/about-team.md"
- type: trust_bar
items:
- text: "Founded 2020"
- text: "500+ Customers"
- text: "SOC 2 Certified"
# site/content/pages/about-founding.md:
# (plain markdown — rendered as HTML at runtime)
We started in a garage with a simple idea...
# site/content/pages/about-team.md:
Meet the people behind the product...
Related: Sitespec, Section Types, Directive Syntax, Copy Md
Static Assets¶
Static asset serving convention for Dazzle projects. Project-level images and assets are placed in {project_root}/static/ and served at /static/*. Framework assets (dz.js, dz.css, favicon) are served automatically from the framework directory. Project files take priority over framework files when paths overlap (shadow/override).
Syntax¶
# Project directory layout:
my-project/
├── static/
│ └── images/
│ ├── hero-office.webp # → /static/images/hero-office.webp
│ ├── logo.png # → /static/images/logo.png
│ └── team-photo.jpg # → /static/images/team-photo.jpg
├── dsl/
├── site/
└── dazzle.toml
# Framework assets (served automatically):
/static/js/dz.js # Dazzle micro-runtime
/static/css/dazzle.css # Dazzle base styles
/static/assets/dazzle-favicon.svg # Favicon
Example¶
# In sitespec.yaml — reference project images:
pages:
- route: "/"
type: landing
sections:
- type: hero
headline: "Welcome"
media:
kind: image
src: "/static/images/hero-office.webp"
alt: "Office"
- type: split_content
headline: "Our team"
media:
kind: image
src: "/static/images/team-photo.jpg"
alt: "Team photo"
alignment: right
# The scaffold command creates static/images/ automatically:
# sitespec(operation="scaffold")
Related: Sitespec, Section Types
App Scripts¶
Custom client JS threading ([ui] app_scripts). Project files in static/js/*.js are served automatically, but a script is only loaded when it's referenced from the page <head>. To thread your own client JS (custom islands, controllers) into the app shell, list the served URLs under [ui] app_scripts in dazzle.toml:
The scripts are appended to the app-shell <head> after the framework bundle, in declared order (so they can depend on the framework runtime). Point at any served path; an empty/absent list leaves the framework-only script set unchanged.
In production/staging everything the chrome links is content-hashed in the path (/static/js/charts.<sha8>.js, served immutable) — the framework bundle, these scripts, the project theme entry at /static/themes/<name>.css, static/css/custom.css and renderer assets() (#1793). Never hand-bump ?v=NN: an entry with a query string is linked un-hashed with a boot warning. A theme entry's absolute /static/... @imports are hashed too (recursively; editing an imported sheet changes the entry's URL); relative @imports and url() sub-resources are not followed.
Related: Sitespec, Section Types
Topbar Title¶
App-shell topbar title ([ui] topbar_title, #1794). The sidebar header always shows the app name; by default the topbar title repeats it. Set topbar_title in dazzle.toml to change what the topbar shows:
"page" shows the current surface or workspace title (the app name when the page has none), which frees the narrow-viewport topbar from a duplicated app name. Any other value fails manifest load with [ui] topbar_title must be true, false, or 'page'.
Related: App Scripts
Page Purpose¶
Switches for the ux: purpose: line the app shell renders above the breadcrumb (.dz-page-purpose, #1811). The purpose text always stays in the IR, dazzle inspect and the compliance docs; only the rendering is suppressed.
surface task_list "Tasks":
ux:
purpose: "Triage the open tasks"
show_purpose: false # this surface only (default true)
App-wide off means off: show_purpose: true on a surface does not override [ui] page_purpose = false.
Related: Topbar Title
Client Events¶
Client-side events host JS can listen for (#1845). Dazzle bundles htmx 4, which dispatches colon-namespaced events only: htmx:before:request, htmx:config:request, htmx:after:request, htmx:before:swap, htmx:after:swap, htmx:after:settle, htmx:after:init, htmx:error. A listener on an htmx 2 camelCase name (htmx:afterSettle, htmx:configRequest) or an htmx 2 handler attribute (hx-on::after-swap, hx-on--after-swap) never fires and raises no error. dazzle validate and dazzle lint warn about them, with file:line and the htmx 4 name, in the project's static/**/*.js and *.html, templates/**/*.html and routes/ overrides (.py and .html); vendor/ and node_modules/ directories and *.min.js files are skipped.
dz:region-loaded is Dazzle's own contract for "a workspace region's content was swapped in", so host enhancements need not key off htmx internals:
document.addEventListener("dz:region-loaded", function (e) {
// e.target is the region element ([data-dz-region]); e.detail.name its region name
enhanceLabels(e.target);
});
It is a bubbling CustomEvent dispatched on the [data-dz-region] element after the swap settles and component-bridge widgets are mounted, with detail.name set to the region's data-dz-region-name. It fires once per swap whose target is the region or lies inside it (the first fetch of a lazy region, a refresh, a filter change, a row swapped in place). It does not fire on the initial page load; run the same enhancement on DOMContentLoaded for server-rendered content.
The CSRF header needs no host listener: dz-csrf.js copies the dazzle_csrf cookie into X-CSRF-Token on every unsafe htmx request, so an htmx:configRequest CSRF listener can be deleted rather than renamed.
Related: App Scripts, Htmx
Adaptive Ui¶
Usage-driven UI adaptation is opt-in (#1843). Dazzle records usage events (first focus on a form field, clicks on heading actions) in _dazzle_usage_events either way; [ui] adaptive_ui decides whether that signal may change what a page renders. The default is false: every page renders as declared, so the UI you tested is the UI users get.
[ui]
adaptive_ui = true # every adaptation
# adaptive_ui = ["combobox", "autofocus"] # or name the ones you want
| Name | What changes once a tenant crosses the usage floor |
|---|---|
combobox |
a plain select with 8+ options becomes the searchable combobox |
autofocus |
the most-engaged plain form field gets autofocus |
actions |
workspace heading actions reorder by click frequency |
columns |
auto-derived list columns keep heavily-engaged fields |
Any other name fails manifest load. A field's own widget= always wins: field deadline_type "Type" widget=select pins a plain select even when combobox is on.
Related: Page Purpose, Widget Combobox