Skip to main content

Golem Documentation

Michael Bernstein

Theme Development & Chameleon TAL

Golem themes provide complete control over the layout, typography, aesthetic styling, and client-side behavior of generated documentation portals. Built on top of Chameleon Zope Page Templates (.pt) and standard TAL (Template Attribute Language), Golem couples powerful declarative templating with modern, parameterized CSS Custom Properties.

Theme Architecture & Layout Structure

A Golem theme is a self-contained directory containing layout templates and static assets. Golem locates and resolves themes using the following hierarchy:

  1. Explicit Custom Template: A template file designated in templates_dir (e.g. templates/page.pt or templates/skeleton.pt).
  2. Project-Local Theme Folder: Located at themes/<theme_name>/ (e.g. themes/mytheme/skeleton.pt).
  3. Packaged Plugin Theme: Discovered via Python package entry points in the golem.themes group.
  4. Built-in Default Theme: Shipped directly inside the golem package at src/golem/templates/default/skeleton.pt.

Standard Theme Directory Structure

Standard Theme Files
TEXT
themes/mytheme/
├── skeleton.pt         # Main HTML5 Chameleon base template
└── static/             # Theme static assets (stylesheets, fonts, images, scripts)
    ├── css/
    │   └── theme.css
    ├── js/
    │   └── theme.js
    └── images/
        └── logo.svg

When Golem builds your documentation site, static assets in themes/<theme>/static/ are automatically synchronized into the output directory under dist/static/.

Template Context Variables

When rendering skeleton.pt, Golem passes a comprehensive set of template variables to Chameleon:

Variable

Type

Description

site_title

str

Title of the website configured in golem.toml or pyproject.toml (default: "Golem Docs").

title

str

Title of the current document extracted from the top-level AsciiDoc header (= Document Title) or front-matter.

site_author

str

Configured site author name or organization (default: "Anonymous").

site_url

str \| None

Base URL of the website if configured (useful for <link rel="canonical"> tags).

generator_version

str

Active version string of the Golem engine (e.g. 0.1.0a3).

body_html

str

Pre-rendered semantic HTML5 content generated from the AsciiDoc document body.

nav_tree

list[dict]

Hierarchical site map data structure containing {title, url, path, children} dictionary nodes.

nav_html

str

Pre-rendered semantic HTML5 navigation list (<nav class="golem-nav">...).

toc_html

str

Rendered Table of Contents HTML unordered list generated from document headings (h2, h3, etc.).

current_path

str

Path of the source document relative to the content root directory.

prev_page

dict[str, str] \| None

Previous document in sequential navigation order ({title, url}).

next_page

dict[str, str] \| None

Next document in sequential navigation order ({title, url}).

pygments_css

str \| None

Server-generated Pygments syntax highlighting CSS rules for light/dark mode.

body_class

str

Class name string extracted from :body_class: header attribute.

content_class

str

Class name string extracted from :content_class: header attribute.

custom_css

list[str]

List of custom stylesheet URLs or paths injected from configuration.

custom_js

list[str]

List of custom script URLs or paths injected from configuration.

breadcrumbs

list[dict]

Ordered breadcrumb trail from root to current page with title, url, and is_current (injected by nav_helpers).

source_edit_url

str \| None

Web URL to edit the source document on GitHub/GitLab (injected by source_links).

source_repo_url

str \| None

Web URL to the repository homepage (injected by source_links).

source_view_url

str \| None

Web URL to view the raw source document on GitHub/GitLab (injected by source_links).

site_index

dict[str, dict]

Alphabetized document index mapping letters to terms and locations (injected by index when page has :page-role: index).

site_glossary

dict[str, list[dict]]

Alphabetized glossary mapping letters to term definitions (injected by glossary when page has :page-role: glossary).

Chameleon TAL & METAL Syntax Reference

Chameleon templates use standard TAL (Template Attribute Language) and METAL (Macro Extension Template Attribute Language) XML attributes to inject dynamic data and construct modular layouts without breaking standard HTML syntax:

TAL Attributes

  • tal:content="variable": Replaces the element's text content with an HTML-escaped string value.
  • tal:content="structure variable": Injects raw HTML markup without escaping (essential for body_html, nav_html, and toc_html).
  • tal:replace="structure variable": Replaces the containing HTML tag itself with raw markup.
  • tal:condition="variable": Renders the element conditionally only if the expression evaluates to truthy.
  • tal:repeat="item collection": Loops through an iterable, repeating the element for each item.
  • tal:attributes="attr expression": Dynamically sets HTML element attributes (e.g. tal:attributes="href item.url").
  • ${expression}: String interpolation syntax for inline variable substitution within text and attributes.

METAL Attributes

  • metal:define-macro="name": Defines a reusable layout macro that can be used or extended by other templates.
  • metal:use-macro="expression": Replaces the element and its children with the body of the specified macro.
  • metal:define-slot="slot_name": Designates an extension slot within a macro that child templates can override.
  • metal:fill-slot="slot_name": Provides replacement markup for a designated macro slot when expanding a macro.

CSS Theme Custom Properties (--golem-*)

The default Golem theme ("Workbench" / Fired Clay aesthetic) is engineered entirely with parameterized CSS Custom Properties (--golem-*). Theme developers can completely re-skin Golem by overriding these variables in CSS without modifying the underlying HTML template.

Light Mode Palette Tokens

Token

Default Value

Role & Usage

--golem-bg

#f7f4ef

Main document background color (warm parchment).

--golem-surface

#f2ede8

Elevated surfaces: header, sidebar navigation, footer, admonition backgrounds.

--golem-code-bg

#ece7de

Background for inline code spans (<code>) and block code listings (<pre>).

--golem-text

#1e1a16

High-contrast primary reading text and headings.

--golem-text-muted

#6b5d52

Secondary captions, metadata, table headers, and inactive links.

--golem-primary

#8b3a12

Brand accent color (terracotta / fired clay) used for active links, hover states, and key highlights.

--golem-primary-hover

#6b2a08

Interactive hover and active focus state for primary brand elements.

--golem-border

#cec8bf

Subtle borders for sidebar dividers, code blocks, tables, and section separators.

--golem-link

#8b3a12

Standard hyperlink text color.

--golem-link-hover

#6b2a08

Hyperlink hover state color.

--golem-link-visited

#3e2518

Visited hyperlink text color.

--golem-note

#2d6a5a

Accent border color for NOTE admonitions (deep teal).

--golem-tip

#6e7818

Accent border color for TIP admonitions (olive green).

--golem-important

#8b3a12

Accent border color for IMPORTANT admonitions (terracotta).

--golem-warning

#b58a00

Accent border color for WARNING admonitions (warm amber).

--golem-caution

#a31818

Accent border color for CAUTION admonitions (crimson red).

--golem-texture

url("data:image/svg+xml,...")

Sub-perceptible SVG fractal noise texture overlay applied to the page body.

Dark Mode Palette Overrides

Golem automatically supports dark mode via @media (prefers-color-scheme: dark). The dark theme uses charcoal and warm ember tones:

Dark Mode Custom Properties
CSS
@media (prefers-color-scheme: dark) {
    :root {
        --golem-bg: #170f0b;
        --golem-surface: #1e1410;
        --golem-code-bg: #2a1e17;
        --golem-text: #f0e4d8;
        --golem-text-muted: #9a7a68;
        --golem-primary: #d4692a;
        --golem-primary-hover: #e07a3a;
        --golem-border: #3d2a20;
        --golem-link: #d4692a;
        --golem-link-hover: #e07a3a;
        --golem-link-visited: #8a4c32;

        /* Admonitions */
        --golem-note: #4a9a8a;
        --golem-tip: #7aaa3a;
        --golem-important: #d4692a;
        --golem-warning: #d4a020;
        --golem-caution: #c04040;
    }
}

Typography Tokens

Golem utilizes four distinct font tokens corresponding to functional typography roles:

Token

Default Fallback Stack

Purpose

--golem-font-display

'Source Serif 4', Georgia, serif

Document titles (h1), section headings (h2, h3), and site branding.

--golem-font-body

'Source Serif 4', Georgia, serif

Main narrative paragraphs, lists, blockquotes, and prose content.

--golem-font-ui

'Source Sans 3', system-ui, -apple-system, sans-serif

Sidebar navigation items, table of contents links, metadata badges, table headers, and footers.

--golem-font-mono

'Source Code Pro', SFMono-Regular, Menlo, Monaco, Consolas, monospace

Code blocks (<pre><code>), inline code (<code>), keyboard shortcuts (<kbd>), and terminal snippets.

Typographical Scale, Optical Sizing & Line-Height

Golem embraces modern CSS variable fonts with optical sizing controls and proportional leading:

  • Optical Sizing (opsz):
    CSS
    body {
        font-optical-sizing: auto;
        font-variation-settings: "opsz" 12;
        line-height: 1.75;
    }
    
    #golem-content h1 {
        font-variation-settings: "opsz" 36;
        line-height: 1.2;
        letter-spacing: -0.01em;
    }
    
    #golem-content h2 {
        font-variation-settings: "opsz" 24;
        line-height: 1.3;
    }
    
    #golem-content h3 {
        font-variation-settings: "opsz" 18;
        line-height: 1.4;
    }
    
    pre, .listingblock pre {
        line-height: 1.55;
    }
  • Container Sizing & Readability:

    The main reading column is constrained for optimal typographical line length (60–75 characters per line):

    CSS
    #golem-content {
        flex: 1;
        padding: 2.5rem 3.5rem;
        max-width: 860px;
    }
  • Responsive Breakpoints:
    CSS
    /* Collapses right Table of Contents on medium viewports */
    @media (max-width: 1100px) {
        #golem-sidebar-right { display: none; }
        #golem-content { padding: 2rem 2.5rem; }
    }
    
    /* Stacks navigation and reading pane into single column on mobile */
    @media (max-width: 800px) {
        #golem-wrapper { flex-direction: column; }
        #golem-sidebar-left {
            width: 100%;
            border-right: none;
            border-bottom: 1px solid var(--golem-border);
        }
        #golem-content { padding: 1.5rem 1.25rem; }
    }

Loading Custom Web Fonts & External Stylesheets

You can load custom web fonts and external stylesheets across your documentation site using the custom_css setting in your configuration file (golem.toml or pyproject.toml).

In golem.toml

golem.toml
TOML
[site]
title = "My Project Docs"
custom_css = [
    "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap",
    "/static/css/custom.css",
]
custom_js = [
    "/static/js/theme-switcher.js",
]

In pyproject.toml

pyproject.toml
TOML
[tool.golem.site]
title = "My Library Documentation"
custom_css = [
    "https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;600&family=Outfit:wght@400;600;700&display=swap",
    "/static/css/custom.css",
]

Applying Custom Fonts in static/css/custom.css

Once loaded, assign the font families to Golem's typography tokens:

static/css/custom.css
CSS
:root {
    --golem-font-display: 'Outfit', sans-serif;
    --golem-font-body: 'Outfit', sans-serif;
    --golem-font-ui: 'Outfit', sans-serif;
    --golem-font-mono: 'Fira Code', monospace;
}

Code Listings & Multi-View Component Styling

Golem renders code blocks and multi-view derived listings as structured <figure> components with semantic headers, interactive tabs, language and test role badges, and clipboard copy controls.

DOM Structure & CSS Classes

Standard Listing Block

HTML
<figure class="listingblock" id="block-id">
  <header class="listing-header">
    <span class="listing-title">example.py</span>
    <div class="listing-actions">
      <span class="badge badge-test">test</span>
      <span class="badge badge-lang">PYTHON</span>
      <button type="button" class="listing-copy-btn" aria-label="Copy code to clipboard">
        <svg class="icon-copy" ...></svg>
      </button>
    </div>
  </header>
  <div class="listing-content">
    <pre class="highlight python"><code class="language-python">...</code></pre>
  </div>
</figure>

Multi-View Derived Listing Block

HTML
<figure class="listingblock multi-view">
  <header class="listing-header">
    <span class="listing-title">Admonition Demo</span>
    <div class="listing-tabs" role="tablist">
      <button type="button" class="tab-btn active" data-tab="source" role="tab" aria-selected="true" tabindex="0">AsciiDoc</button>
      <button type="button" class="tab-btn" data-tab="asg" role="tab" aria-selected="false" tabindex="-1">ASG</button>
      <button type="button" class="tab-btn" data-tab="html" role="tab" aria-selected="false" tabindex="-1">HTML</button>
      <button type="button" class="tab-btn" data-tab="preview" role="tab" aria-selected="false" tabindex="-1">Preview</button>
    </div>
    <div class="listing-actions">
      <span class="badge badge-lang">ASCIIDOC</span>
      <button type="button" class="listing-copy-btn" aria-label="Copy code to clipboard">...</button>
    </div>
  </header>
  <div class="listing-panes">
    <div class="tab-pane active" data-tab="source" role="tabpanel">
      <pre class="highlight asciidoc"><code class="language-asciidoc">...</code></pre>
    </div>
    <div class="tab-pane" data-tab="asg" role="tabpanel" hidden="hidden">
      <pre class="highlight json"><code class="language-json">...</code></pre>
    </div>
    <div class="tab-pane" data-tab="html" role="tabpanel" hidden="hidden">
      <pre class="highlight html"><code class="language-html">...</code></pre>
    </div>
    <div class="tab-pane" data-tab="preview" role="tabpanel" hidden="hidden">
      <div class="rendered-preview">...</div>
    </div>
  </div>
</figure>

Component Class Reference

Class Name

HTML Element

Role & Styling Purpose

.listingblock

<figure>

Outer wrapper for code listings. Sets border, background (--golem-code-bg), accent left stripe (--golem-primary), and overflow boundaries.

.listingblock.multi-view

<figure>

Modifier class applied when derived multi-view tabs (render=...) are present.

.listing-header

<header>

Flexbox header bar displaying title, tab controls, language badges, and actions against --golem-surface.

.listing-title

<span>

Displays filename or block title with bold weight (--golem-text) and ellipsis truncation.

.listing-tabs

<div>

Container (role="tablist") grouping interactive tab buttons.

.tab-btn

<button>

Interactive tab switcher (role="tab"). Styled with muted text, transitioning to --golem-primary on .active / aria-selected="true".

.listing-actions

<div>

Right-aligned flex container housing role badges, language pill, and the copy button.

.badge

<span>

Base pill badge styling with uppercase typography (--golem-font-ui) and subtle borders.

.badge-lang

<span>

Pill badge displaying language identifier (e.g. PYTHON, TOML, ASCIIDOC).

.badge-test

<span>

Semantic badge for role="test" doctest blocks styled using --golem-note (teal).

.badge-shared

<span>

Semantic badge for role="shared" state blocks styled using --golem-tip (olive).

.badge-reset

<span>

Semantic badge for role="reset" state-clearing blocks styled using --golem-warning (amber).

.listing-copy-btn

<button>

Clipboard copy trigger. Features hover states, focus rings, and a temporary .copied state with green checkmark styling (--golem-tip).

.listing-panes

<div>

Wrapper for multi-view panes.

.tab-pane

<div>

Individual view panel (role="tabpanel"). Hidden panes receive the [hidden] attribute (display: none !important).

.rendered-preview

<div>

Sandbox container for live rendered HTML in the preview tab. Resets background to --golem-bg and body text to --golem-text.

Design Tokens for Listing Customization

Themes can customize code listings and multi-view blocks by overriding the following CSS custom properties:

CSS
:root {
    /* Code block container & header */
    --golem-code-bg: #ece7de;
    --golem-surface: #f2ede8;
    --golem-border: #cec8bf;
    --golem-primary: #8b3a12;

    /* Badges & Actions */
    --golem-note: #2d6a5a;
    --golem-tip: #6e7818;
    --golem-warning: #b58a00;
    
    /* Typography */
    --golem-font-ui: 'Source Sans 3', sans-serif;
    --golem-font-mono: 'Source Code Pro', monospace;
}

Overriding skeleton.pt in a Custom Theme

To create a fully customized theme or override Golem's default page structure:

  1. Create a theme directory: themes/mytheme/.
  2. Place a skeleton.pt template inside themes/mytheme/skeleton.pt.
  3. Set theme = "mytheme" in golem.toml under [build] (or [tool.golem.build] in pyproject.toml).

Complete Annotated Custom Theme Example

themes/mytheme/skeleton.pt
HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${title} - ${site_title}</title>
    <meta name="generator" content="${generator_version}" />
    <meta tal:condition="site_author" name="author" content="${site_author}" />
    <link rel="canonical" tal:condition="site_url" href="${site_url}" />

    <!-- External and Custom Stylesheets -->
    <tal:block tal:repeat="css_file custom_css">
        <link rel="stylesheet" href="${css_file}" />
    </tal:block>

    <!-- Theme Stylesheet -->
    <link rel="stylesheet" href="/static/css/theme.css" />
</head>
<body>
    <header class="site-header">
        <div class="header-container">
            <a href="/" tal:attributes="href site_url or '/'" class="site-logo">${site_title}</a>
            <span tal:condition="site_author" class="site-author">By ${site_author}</span>
        </div>
    </header>

    <div class="layout-container">
        <!-- Sidebar Navigation -->
        <aside class="sidebar-nav">
            <div tal:condition="nav_html" tal:replace="structure nav_html" />
            <ul tal:condition="not:nav_html and nav_tree">
                <li tal:repeat="item nav_tree">
                    <a href="${item.url}" tal:attributes="href item.url">${item.title}</a>
                </li>
            </ul>
        </aside>

        <!-- Main Document Body -->
        <main class="content-body">
            <h1 tal:condition="title">${title}</h1>
            <div tal:content="structure body_html" />
        </main>

        <!-- Table of Contents -->
        <aside class="sidebar-toc" tal:condition="toc_html">
            <h3>On This Page</h3>
            <div tal:content="structure toc_html" />
        </aside>
    </div>

    <footer class="site-footer">
        <p>Built with Golem ${generator_version}</p>
    </footer>

    <!-- Custom JavaScript Injections -->
    <tal:block tal:repeat="js_file custom_js">
        <script src="${js_file}"></script>
    </tal:block>
</body>
</html>

METAL Slot Contracts & Layout Inheritance

Golem's built-in skeleton.pt template exposes the top-level macro layout and 6 specialized extension slots. Custom themes can either write an entirely custom template from scratch or inherit and selectively override individual slots using metal:use-macro and metal:fill-slot.

METAL Slot Specifications

Slot Name

Target Element

Contract & Usage

head

<head>

Document <head> metadata, <title>, <meta> tags, canonical links, font imports, Pygments CSS rules, and external stylesheet links (custom_css). Themes overriding this slot can inject bespoke web fonts, custom metadata, or analytics scripts while preserving <meta charset="UTF-8"> and viewport declarations.

header

<header id="golem-header">

Global site branding header bar containing the site title link (site_title), optional author attribution (site_author), and navigation toggles. Themes overriding this slot can introduce logos, search inputs, repository shortcut badges, or theme-mode switcher widgets.

navigation

<aside id="golem-sidebar-left">

Left sidebar navigation panel. The default implementation renders inside a collapsible <details class="golem-nav-details"> disclosure widget, prioritizing pre-rendered semantic HTML (nav_html) and falling back to iterating nav_tree. Themes can override this slot to provide accordions, multi-column flyouts, or custom category filtering.

content

<main id="golem-content">

Main document article reading pane. Houses breadcrumb navigation (breadcrumbs), page heading (title), pre-rendered semantic article body (body_html), and sequential pagination cards (prev_page, next_page). Themes overriding this slot can inject reading-time estimates, author avatars, feedback prompts, or custom header banners.

table-of-contents

<aside id="golem-sidebar-right">

Right-hand on-page Table of Contents sidebar. Displays the "On This Page" heading and the rendered heading list (toc_html). Themes can override this slot to add sticky jump links, page metadata sidebars, or hide it on specific page layouts.

footer

<footer id="golem-footer">

Document footer bar. Renders git repository "Edit this page" links (source_edit_url), Golem generator version credits, and custom footer copy. Themes can add custom legal disclaimers, license badges, or secondary navigation links.

Extending Default Slots with metal:use-macro

To customize specific regions without duplicating the entire HTML5 structure, a theme template can use the default macro and fill only the desired slots:

themes/mytheme/skeleton.pt
HTML
<!DOCTYPE html>
<html lang="en" metal:use-macro="default_layout">
    <!-- Customize header to include logo and repository link -->
    <header id="golem-header" class="golem-header custom-header" metal:fill-slot="header">
        <div class="brand">
            <img src="/static/images/logo.svg" alt="Logo" class="logo" />
            <a href="./" tal:attributes="href site_url or root_path">${site_title}</a>
        </div>
        <div class="header-actions" tal:condition="source_repo_url | nothing">
            <a href="${source_repo_url}" class="repo-link" target="_blank" rel="noopener noreferrer">GitHub</a>
        </div>
    </header>

    <!-- Customize footer with copyright and custom links -->
    <footer id="golem-footer" class="golem-footer" metal:fill-slot="footer">
        <div tal:condition="source_edit_url | nothing" class="golem-source-links">
            <a href="${source_edit_url}" target="_blank" rel="noopener noreferrer">Edit this page</a>
        </div>
        <p class="copyright">&copy; 2026 Acme Corp. All rights reserved. Powered by Golem ${generator_version}.</p>
    </footer>
</html>

Distributing Reusable Themes via Python Packages

You can distribute Golem themes as reusable Python packages. Register your theme directory in pyproject.toml using entry points:

pyproject.toml
TOML
[project.entry-points."golem.themes"]
mytheme = "my_theme_package"

When installed, users can select your theme simply by setting theme = "mytheme" in their golem.toml.

TAL

Template Attribute Language. An XML-attribute-based language used by Chameleon to declare conditional rendering, repetition, and content injection directly in HTML/XML markup.

METAL

Macro Expansion for TAL. The METAL namespace allows Chameleon templates to define reusable layout slots (metal:define-slot) and fill them from page templates (metal:fill-slot).

ZPT (Zope Page Templates)

The template format combining TAL and METAL, originating in the Zope web framework. Chameleon implements ZPT with significant performance improvements via compilation.

Chameleon

A fast, compiled Zope Page Templates engine. Golem uses Chameleon to render skeleton.pt and any custom theme templates.

skeleton.pt

The primary Chameleon template file (skeleton.pt) that defines the full HTML page layout for a Golem site, including head metadata, navigation, content area, and footer slots.