Pages and composition
Laying out a template — how pages place sections, and what the framework derives from that rather than asking you to declare.
What it is
pages in template.ts is the site map: an object whose keys are page ids,
whose order is the order the artifact carries, and whose entries each name a
React component. That component is a page — a function of nothing that places
sections and nothing else.
import { defineTemplate, Section, section, Slot, text, website, fact, fill } from "@homepages/concrete";
import icon from "./icon.svg";
const headline = text.medium({
label: "Headline",
cap: 60,
source: fill.write({ reads: [fact.property.description], brief: "What makes the property worth seeing. Write one sentence. Confident and specific." }),
});
const Hero = section(
{ key: "hero", label: "Hero", slots: { headline } },
({ slot }) => (
<Section>
<Slot.Text slot={slot.headline} as="h1" />
</Section>
),
);
// pages/home.tsx — a page takes no props and places sections in order.
const Home = () => <Hero />;
export default defineTemplate({
key: "riverside",
name: "Riverside",
format: website,
icon,
scope: "global",
pages: {
home: { label: "Home", path: "/", page: Home },
},
});The composition — which section instances exist, on which page, in what order — is derived from those pages. You never write it down.
Why it works this way
The platform assembles a published page out of section renders. It has somewhere to put a section and nowhere to put anything else, so a page component is not markup the platform keeps: it is a statement of order. Reading that statement off the component you already wrote, instead of asking you to repeat it in a list, removes the one thing that can fall out of step.
That is also why a page takes no props and reads no input. It is rendered once, at check time, and its answer is stamped into the artifact. A page that branched on the clock, on randomness, or on something the platform supplies would have an answer that stopped being true the moment it was recorded.
The same reasoning fixes how instances are identified. The platform keeps one
content document per instance for the life of a site, so an instance id has to
survive an edit to your layout — and placement order cannot supply that, because
inserting a section at the top would renumber everything under it. Identity
therefore comes from the section's own key, and only a second placement of
the same section has to say anything at all.
How it works
The probe. concrete check, concrete dev and concrete build render each
page component once inside
a recording context. A section placed under that context records its key and
instance id in render order and emits no markup. The recorded sequence is that
page's section list; the union over every page is the template's instance set.
A page may contain only sections. Fragments are fine, and so are wrapper components of your own, as long as what they finally contain is sections:
import type { ReactNode } from "react";
import { Section, section, Slot, text, fact, fill } from "@homepages/concrete";
const headline = text.medium({
label: "Headline",
cap: 60,
source: fill.write({ reads: [fact.property.description], brief: "What makes the property worth seeing. Write one sentence. Confident and specific." }),
});
const Hero = section(
{ key: "hero", label: "Hero", slots: { headline } },
({ slot }) => (
<Section>
<Slot.Text slot={slot.headline} as="h1" />
</Section>
),
);
const Stack = ({ children }: { children: ReactNode }) => <>{children}</>;
export const Home = () => (
<Stack>
<Hero />
</Stack>
);A host element — a <div>, a <main>, a stray string — is a check error naming
the page, because the probe finds markup left over once the sections have
recorded themselves and the platform has nowhere to put it. Chrome that renders
is a section, not page markup.
One section is one instance, however many pages place it. Placing the same section value on two pages gives you a single instance rendered on both, which is exactly what a header and a footer want: the user edits it once and sees it everywhere. A second instance of that section names itself:
import { Section, section, Slot, text, fact, fill } from "@homepages/concrete";
const headline = text.medium({
label: "Headline",
cap: 60,
source: fill.write({ reads: [fact.property.description], brief: "What makes the property worth seeing. Write one sentence. Confident and specific." }),
});
const Hero = section(
{ key: "hero", label: "Hero", slots: { headline } },
({ slot }) => (
<Section>
<Slot.Text slot={slot.headline} as="h1" />
</Section>
),
);
export const Gallery = () => (
<>
<Hero />
<Hero instance="hero-2" />
</>
);The default id is the section's key with -1 after it. One id naming two
different sections, or one page placing the same id twice, is a check error.
Paths and optionality. A website page carries a path — "/" for the root,
one lowercase-kebab segment otherwise — and a label the editor's page bar
shows. optional: true lets the user switch a whole page off; it then publishes
nothing and drops out of the navigation a section reads. The root page can never
be optional, because a site has to answer /.
A rendered template — a deck, a social post, a print sheet — has pages too, but
they are sheets and frames rather than URLs, so they carry no path. Which of
the two you are writing is settled by format, and the types follow it: a
path on a slide, or a website page without one, fails to compile rather than
to validate.
Row pages. A rendered page stacks its sections top to bottom. One that
declares direction: "row" lays them side by side instead, each section setting
its own width and standing the page tall: that is how a folded print piece is
written. The format is the flat sheet, and each printed side is one row page
whose sections are its panels, left to right, so the editor and the PDF both show
the sheet as it prints. Every section a row page places must be required and
may not declare a visibility rule, because a panel that dropped out would shift
every later one onto the wrong fold; concrete check refuses either.
Canvases. A canvas is one editing surface in the editor's canvas bar: a label
and the page ids it presents, in display order. Declare canvases to group pages
under one surface. Omit it and the class default is stamped explicitly — one
canvas per page for a website, a single canvas holding every page for a rendered
template.
What it is not
A page is not a layout component. It renders in no browser, ships in no bundle, and receives no props; everything it might have branched on belongs to a section instead.
It is not a route handler either. A path is data the platform routes on, and
your component never sees a request, a URL or a parameter.
And the composition is not a file. There is no manifest to keep in step with your pages, which is the whole point — the pages are the manifest.
Where next
Add a page and
Share a header and footer
are the two recipes over a composition.
template.ts states pages, path, optional and
canvases member by member, and Formats is the set
format chooses from. The command that renders your pages and reports on them is
concrete check, and the two errors it raises here
resolve at pages/non-section-markup and
pages/composition-invalid.
