Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Theme Settings

A theme declares its own settings under form in the config; the theme page shows them as a form, and templates read the values beside the theme’s keys.

name: Acme
form:
  fields:
    site_name:
      label: Site name
      type: text
    tagline:
      label: Tagline
      type: textarea
<h1>{{ theme.site_name }}</h1>
<p>{{ theme.tagline }}</p>
KeyMeaning
formA form descriptor (see Form Descriptor); the fields are listed under Form Fields.
theme.<field>The saved value, read in any template beside theme.code, theme.name, theme.author, theme.homepage and theme.description (see Properties).

A child theme without a form uses its parent’s; the values are each theme’s own. A field named code, name, author, homepage or description is refused.

Read and save the values from Rust

let chain = store::chain(&db, "acme").await?;
let fields = store::form_fields(&chain);
store::save_settings(&db, "acme", &serde_json::json!({ "site_name": "Acme" })).await?;
let values = store::find_theme(&db, "acme").await?.unwrap().settings;

Render the form on a module screen

A module’s own screen renders and collects such a form through the route context:

let form = ctx.value_form(&fields, "acme")?;
let markup = form.render(&values, &shell);
let saved = form.collect(&data)?;
let page = shell.page_with(PageHead::new(title).assets(&form.assets()), markup);

form.assets() lists the scripts and styles the fields’ types declare; pass them to the page head.