Theme tutorial · build an editable announcement
Copy the Lite theme, define editable fields, render an announcement, and check the homepage and workbench.
Verified result. With the three samples below copied into a Lite theme copy, the static homepage rendered the instance heading Open day in May and its body. The default workbench scenario rendered What’s new and the default body. Both use the same render component, with the page instance supplying its own settings.
You can already edit a page in the admin. Now imagine a studio client wants to change a short announcement every month. Build a section with two fields, then compare its default copy with the content of an actual page instance.
Copy a working starting point
After installing the repository dependencies, copy the Lite theme to a new directory. This example uses theme-lab. The demo loads this copy and local mock content.
cp -R packages/theme-lite packages/theme-lab
THEME_DIR=theme-lab npm run dev:demo
Open localhost:4321 and confirm that you see the Lite homepage. Leave the server running while you add the files below.
Define editable fields
Create sections/announcement/setting.ts in your copy. The directory name announcement is the section key. Use the page group because Lite’s page.main slot supports it.
import { defineSection } from "@platform/theme/define.ts";
export default defineSection({
label: "Announcement",
groups: ["page"],
settings: [
{ type: "text", id: "title", label: "Heading", locale: true, default: "What’s new" },
{ type: "textarea", id: "body", label: "Message", locale: true, default: "Add a short announcement." },
],
messages: [],
});
Field IDs are the keys the template reads. Set locale: true for text managed by language. If you rename a field ID after instances have been saved, plan how to preserve their existing values.
Render the fields
Create render.astro in the same directory. Read instance values with the theme contract’s useSection. Keep the fragment marker so editor preview can address the section. Use an H2 so the page can keep its own H1.
---
import { useSection, type SectionProps } from "@platform/theme/use.ts";
const section = useSection(Astro.props as SectionProps);
const title = section.text("title");
const body = section.text("body");
---
<section class="lite-panel" data-cms-fragment={section.id}>
{title && <h2>{title}</h2>}
{body && <p>{body}</p>}
</section>
Verify a page instance
Open mocks/pages/home.ts in your copy. Add this item at the end of the slots["page.main"] array. The file already imports defineMockSection.
defineMockSection({
key: "announcement",
settings: {
title: "Open day in May",
body: "Visit the studio to meet the people behind the website.",
},
}),
Refresh the homepage and look for Open day in May. Then select Announcement in the section workbench. Its default example should show What’s new. The different headings confirm which view uses page-instance content and which uses defaults.
Run this command to verify the static export. It writes the selected demo to deploy/demo/.
THEME_DIR=theme-lab npm run build:demo
Diagnose a missing or incorrect section
| Symptom | Check first |
|---|---|
| Announcement is missing in the workbench | Confirm that the folder is under the selected theme-lab and both files are named correctly |
| The workbench shows it but the homepage does not | Check the mock key, page.main slot, and its page group |
| The homepage has the wrong copy | Compare title and body in the instance settings with the keys the renderer reads |
| The demo works and the production editor needs real content | Select your theme in the application, create a real section instance in the admin, and publish it. The workbench and static demo use mock data. |
Continue with themes and templates and the technical reference.