The Big Picture

  • One site is active per deployment. You can keep several sites (for example to A/B test designs) and switch the active one in Admin > Sites.
  • One site is the default (the Default tag in Admin > Sites): it cannot be deleted and becomes active when no other site is. On a fresh install it is the starter site, and the tag never moves: new sites are never the default, and the forms have no switch for it. Default and active are separate: the default site does not have to be the one being served.
  • A site is a database row: name, title, tagline, contact email and theme, plus a folder modules/site/<name>/ holding an optional init.ts.
  • A theme (themes/<theme>/) holds the HTML frame: layout.html, home.html and any pages of its own. Content pages come from Admin > Pages.
  • Content lives in Admin > Pages, shared by all sites: each page is at /<slug> or is a section of the home page, and joins the menu when Show in navigation is on. A page at /<slug> shows its content only, not its title: give the content its own heading. Changing a published page's slug is safe: the old address redirects to the new one (see Admin > Pages > Redirects). A theme can be just a frame: layout.html and home.html.
  • Uploads are content only. Themes can be added as ZIPs in Admin > Themes and images and files in the Media Manager; server code (init.ts) is never uploaded, it is written by a developer and deployed with git.

1. The Theme

Designers: How to create a theme explains themes step by step without programming. This section is the developer's reference.

themes/acme/
├── layout.html        required: header, menu, footer and <!-- @content -->
├── home.html          ->  /  (can show the pages marked "Section of the home page")
├── pricing.html       ->  /pricing        optional: every page file is a route
├── 404.html           optional: not-found page        (else starter's)
├── 500.html           optional: error page            (else starter's)
├── maintenance.html   optional: maintenance mode page (else starter's)
├── _footer-cta.html   files starting with _ are never routes
├── collections/       optional: your look for Collections pages (list.html, details.html,
│                      embed.html; or collections/<collection>/... for one collection)
├── images/            the theme's own images: favicon.svg (linked by the layout and
│                      served at /favicon.ico), logo, backgrounds
├── css/  js/  fonts/
└── theme.json         optional: { "name": "Acme", "description": "..." } (Admin > Themes)
  • Every .html page is a route: home.html is /, any other x.html is /x. No code needed. File names use lowercase letters, digits and dashes.
  • Missing pages fall back to the starter theme's version (home, 404, 500, maintenance), so a theme only needs layout.html to work. starter is the fallback theme and the theme of a fresh install; it has no other pages, so About, Contact and the like come from Admin > Pages (or from your theme's own files).
  • A variant of a theme needs only layout.html and a stylesheet: dark-slate is the starter theme in dark colours. Its css/style.css imports /themes/starter/css/style.css and overrides the colour variables (--bg-main, --text-main, --primary, ...). It has its own home.html (a copy of starter's, to change freely); the pages it lacks (404, 500, maintenance) come from starter.
  • Pages from Admin > Pages are at /<slug> (/page/<slug> redirects there). A theme page or module route with the same address wins, so the Pages editor refuses slugs that the active site's theme or a module already uses.
  • Maintenance: Switch maintenance mode on the active site's row in Admin > Sites (the Maintenance column). In maintenance mode visitors see the active theme's maintenance.html; signed-in staff (administrators, managers, editors) and IP addresses listed in Settings > Maintenance see the site as usual. The page gets {{ maintenanceMessage }} and {{ maintenanceUntil }} from Settings > Maintenance.
  • Collections (Admin > Collections) have built-in pages at /c/<collection>; a theme restyles them with collections/list.html, details.html and embed.html, for every collection or under collections/<collection>/ for one. Folders are never routes. See How to create a collection.
  • Templates only hold page content. Header, menu and footer belong in layout.html.
  • The theme's own images (favicon, logo, backgrounds) go in its images/ folder: url('../images/bg.jpg') in CSS, /themes/{{ siteTheme }}/images/logo.svg in HTML. Link the icon in the layout with <link rel="icon" href="/themes/{{ siteTheme }}/images/favicon.svg">; /favicon.ico also serves the active theme's images/favicon.ico, .png or .svg (else uploads/favicon.png). Content images (photos in pages) belong in the Media Manager instead.
  • Raw .html files are never served from /themes/; only assets (CSS, JS, images, fonts) are.
  • Caching: theme pages are cached for anonymous visitors, for 5 minutes by default (Settings > Cache > Keep theme pages for; signed-in users always see the latest version), one entry per page whatever the query string. Restarting the server clears cached pages (so a deploy shows new templates at once); after editing a template on a running server, clear the cache in Admin > Cache to see it as a visitor. Browsers keep theme CSS and JS for up to a day.

The layout

<!DOCTYPE html>
<html lang="{{ lang }}">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="{{ site.description }}">
  <title><!-- @title --></title>
  <link rel="icon" href="/themes/{{ siteTheme }}/images/favicon.svg">
  <link rel="stylesheet" href="/themes/acme/css/style.css">
  <script>window.__CSRF_TOKEN__ = "";</script>
  <!-- @head -->
  <!-- @styles -->
</head>
<body>
  <header>
    <a href="/">{{ site.title }}</a>
    <nav>
      {{#each siteNavItems}}
        <a href="{{ path }}" class="{{#if isActive}}active{{/if}}">{{ label }}</a>
      {{/each}}
    </nav>
  </header>

  <main><!-- @content --></main>

  <footer>{{ site.tagline }} · © {{ site.year }} {{ site.title }}</footer>
  <!-- @scripts -->
</body>
</html>

Keep the four slots: <!-- @content --> receives the page, @head the canonical address, structured data (JSON-LD), and the social and analytics tags (Settings > SEO), and @styles / @scripts the CSS and JavaScript of the widgets on the page (the contact form needs its script). Keep the viewport line, or phones show the desktop layout zoomed out. The fastest start is a copy of themes/starter/, which is already responsive (phone menu, stacked columns).

The menu

siteNavItems contains, in order: Home (plus About and Contact only when the theme has about.html / contact.html); links added by enabled modules (for example Products); then every published page with Show in navigation turned on in Admin > Pages, in its navigation order. A page's link is /<slug>, or /#<slug> when it is a section of the home page. A site's init.ts can replace the first links with its own list (module links and Pages are still added). Disabling a module in Admin > Modules removes its link.

Home page sections (one-page sites)

In Admin > Pages, Display: Section of the home page puts a page on the home page instead of at its own address; its menu link scrolls to it and /<slug> redirects to /#<slug>. The theme's home.html decides where the sections go:

<section class="hero"><h1>{{ site.title }}</h1></section>

{{#each homeSections}}
  <section id="{{ slug }}">
    <h2>{{ title }}</h2>
    {{{ content }}}
  </section>
{{/each}}

Each section has slug, title, label (its menu label), description (the page's Meta Description, for a subtitle) and content (the page's HTML; widget and collection codes in it work). The one-page theme is a complete example: numbered sections, title and description on the left, content on the right, and the menu following the section being read. Sections come in navigation order; drafts are left out. A theme whose home.html does not use homeSections simply does not show them, and the Pages editor says so. Mix freely: sections for the home page plus separate pages such as Privacy.

Useful template variables

The most used ones are below; Template Variables lists every one, where it is available, and the five site details editors can type in page text.

VariableValue
{{ site.title }}, {{ site.tagline }}, {{ site.year }}Active site title, its tagline from Admin > Sites (empty when none; for the hero and footer), current year
{{ site.email }}The site's Contact form email (empty when none); also usable in page text
{{ site.description }}The page's description for search engines (for <meta name="description">): the page's own Meta Description, else Settings > SEO > Default description, else the tagline
{{ siteTheme }}The active theme's folder name, for asset paths (/themes/{{ siteTheme }}/css/style.css)
{{ currentSite.contact_email }}Active site's contact email
{{#each homeSections}}Home page only: the pages shown as sections (see above)
{{ lang }}Language the page is rendered in (for <html lang>)
{{ csrfToken }}CSRF token for forms (_csrf field or x-csrf-token header)
{{#if isLoggedIn}}, {{ user.name }}Signed-in visitor
{{ widgets:render type="card" instance_name="hero" }} or [[card, hero]]Embed a widget (see How to create a widget for overrides)
{{ page='about-us' }}Embed a page's content
{{ collections:render collection="testimonials" limit="4" }}Embed a collection's items (see How to create a collection)

The contact form

No code needed: the Contact form widget type (widgets/contact-form/) is a ready form. Insert it into any page with the editor's Widget button ({{ widgets:render type="contact-form" instance_name="contact-form" }}); a fresh install's Contact page already has it. Messages go to the active site's contact email (Admin > Sites), or to the admin email in Settings > General when the site has none; extra recipients, the thank-you text and the per-minute limit are in Settings > Contact Form.

A theme can also build its own form and post to the same endpoint:

await fetch('http://localhost:3000/api/v1/site-manager/contact?site=carnival-cms', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', 'x-csrf-token': window.__CSRF_TOKEN__ },
  body: JSON.stringify({ name, email, message }),
});

Adding a theme in the admin (Admin > Themes)

Admin > Themes lists every theme folder: its name, description, status, the sites that use it and where it came from (Built-in: in the repository; Uploaded: added in the admin).

  • Add Theme: a ZIP of the theme folder, a Theme name (empty: the name in the theme's optional theme.json, else the folder name), a Description (empty: theme.json's description) and a Status switch. The folder name comes from the ZIP's file name (ocean-breeze.zip becomes uploaded-themes/ocean-breeze/) and cannot change. The ZIP must contain layout.html; a single wrapping folder is removed; only page, style, script, image, font and media files are accepted (no .ts, .php, ...). An existing theme is never overwritten.
  • Upload new version (edit an uploaded theme): the ZIP's files replace the theme's files with the same path and new files are added; files the ZIP does not contain stay as they are. A partial ZIP (say css/style.css only) is fine.
  • Layout (edit a theme): the page layout the theme is built around, one of 18 (one column, columns, sidebars, hero, cards grid, gallery, landing page, ...), chosen from a dropdown with each layout's picture; the picture appears in the list's Layout column. It describes the theme for the people choosing one; it does not change how the theme renders.
  • Status: only enabled themes are offered in the site forms. The starter theme (the fallback) is always enabled. A theme that sites use cannot be disabled or deleted: the warning names those sites; switch them to another theme first.
  • Duplicate (edit a theme, Files): any theme, built-in ones too, copied as a new uploaded theme to change freely. Download ZIP: any theme as a ZIP (a backup, or to add it to the code).
  • Edit files and Preview (administrators only): a code editor for an uploaded theme's files, with earlier versions to restore, and a private preview of the public site in any theme (View Site always shows the real theme and ends a preview). See How to create a theme.
  • Delete: uploaded themes that no site uses; removes the folder. Built-in themes are part of the code: change or remove them in the repository.
  • Who: administrators and managers (the Themes row in Roles & Permissions); editors only when granted. A theme's JavaScript runs on the public site, also while an administrator browses it, so grant this only to people you trust with admin rights.
  • Hosting: uploaded themes are kept in uploaded-themes/, apart from the code (on Render, on the persistent disk), so deploys keep them; back that folder up with uploads/. A theme whose folder is gone shows as Files missing; upload a new version to restore it. Themes uploaded before this folder existed are moved there at startup.

2. Add the Site

A fresh install already has one: the starter site ("My Site") with the starter theme, as the default and active site and starter pages in Admin > Pages (About, Contact with the contact form, and Privacy, each its own page at /<slug>; About and Contact are in the menu). Rename it in Admin > Sites and replace the text in Admin > Pages. The repository also holds modules/site/carnival-cms/ (the project's own site, no code yet), so a fresh install lists a second site, carnival-cms, inactive and on the starter theme until you pick another; delete it in Admin > Sites and remove its folder if you do not need it.

In the admin

Admin > Sites > New Site:

  • Title, tagline: shown by the theme ({{ site.title }}, {{ site.tagline }}). The site's name (its folder name, e.g. Acme Shop becomes acme-shop) is made from the title and cannot be changed later. A site cannot be named after a module (e.g. products, users), because its custom code would replace that module, nor thumbs (the Media Manager's thumbnail folder).
  • Theme: the themes enabled in Admin > Themes (starter is preselected). New themes are added there, not in the site form (see "Adding a theme in the admin" above). A site keeps its theme if the theme is disabled later; its edit form then lists it as "(disabled)".
  • Contact form email: where this site's contact form messages go. It is not the admin notification email (Settings > General), which receives system notices such as new registrations and is the fallback when this field is empty.
  • Active: off by default, so you can prepare the site (theme, pages) and activate it in Admin > Sites when it is ready. Turn it on to serve the site as soon as it is created.

Saving creates the database row and modules/site/<name>/init.ts (comments only); no restart is needed. The edit form lets you change the title, tagline, theme and contact form email later.

From the terminal

bun run make:site acme --theme acme --title "Acme" --email hello@acme.com --activate

This does the same as the admin form (without --theme, the site uses starter; like the form, it refuses a theme that is missing or disabled in Admin > Themes). Without --activate, switch to the site in Admin > Sites.

3. Custom Code (optional)

Open modules/site/<name>/init.ts; it contains commented instructions and an example. Use it when a page needs data, for routes that are not theme pages, for a custom menu, or for a site API. Restart the server after editing it (bun run dev restarts automatically). A site folder added this way (for example from git) gets its site in Admin > Sites at that restart: every folder in modules/site/ without a site gets one, inactive.

import type { AppModule } from '../../../src/core/types.js';
import { dbAll } from '../../../src/core/db.js';

export const acmeSite: AppModule = {
  id: 'acme',              // must equal the folder name
  name: 'Acme',
  version: '1.0.0',
  description: 'Custom code for the Acme site',
  isSite: true,
  site: {
    nav: [                 // optional: replaces the standard links (Home, plus About /
                           // Contact when the theme has those pages)
      { label: 'Home', path: '/', order: 0 },
      { label: 'Pricing', path: '/pricing', order: 1 },
    ],
    routes: [
      // Data for a theme page: rendered with themes/acme/pricing.html
      { path: '/pricing', cacheTtl: 60, handler: async () => ({ plans: await dbAll('SELECT * FROM plans') }) },
    ],
  },
};

Route precedence: routes in the site's init.ts, then the theme's pages, then other modules' fixed routes (for example /products, /c/testimonials), then routes that start with a parameter (Pages at /:slug). A handler that returns plain data is rendered with the theme page named after the path; return a Response for full control.

A one-page site needs no code: use the one-page theme (or any theme whose home.html shows homeSections) and set your pages' Display to "Section of the home page".

4. Switching Sites and A/B Testing

  • Select the active site in Admin > Sites. It stays active across restarts.
  • Statistics record each page view with the site and the theme it was rendered with. The dashboard filters by site and by theme, so you can compare designs.
  • Only one site is live at a time, so variants are compared period by period.

5. Export as a Static Site

In Admin > Sites, the download button on a site's row exports it as plain HTML, CSS and JS files in a ZIP, for any static host (Netlify, GitHub Pages, S3, a plain web server). Any site can be exported, active or not. Enter the address it will have (for sharing links and the sitemap), then upload the ZIP's contents to the root of that address.

  • What is exported: every page the way a visitor who is not signed in sees it (published only): the home page and its sections, pages from Admin > Pages (also those in no menu), collection lists and items, products, widgets and collection embeds; plus every file those pages use (theme CSS, JS and images, widget files, uploaded images, files named in CSS). Each page is <path>/index.html, so /about keeps working; 404.html, sitemap.xml, robots.txt and EXPORT-INFO.txt are added.
  • Lists: page 2 of a list (/c/faq?page=2) becomes /c/faq/page/2/ and its links are rewritten, because static hosts ignore the part after ?.
  • The contact form keeps sending messages to the Carnival3 server (APP_URL), for the exported site's contact email, so the server must stay online.
  • Not part of a static site: sign-in and registration, statistics, maintenance mode and the admin. Keep editing on the Carnival3 server and export again after changes.
  • The site is exported from the server's root (/): host it at the root of a domain or subdomain, not in a subfolder.
  • Hosting the ZIP, step by step (static hosts, shared hosting, XAMPP with a virtual host): see Deploy as a ZIP.

6. Deleting a Site

Deleting removes the database row, and removes modules/site/<name>/ only if it still holds the untouched starter init.ts. A folder with custom code is kept, so its code is never lost; but at the next restart every folder without a site gets one again, so delete the folder too (in git) to remove the site for good. The starter site's folder is always kept: it is part of the repository, so every install has that site. The default site cannot be deleted. Themes, uploads and the site's statistics are never deleted automatically.