Share a header and footer
Every page needs the same chrome, and the user should edit it once rather than once per page.
Goal
A header and a footer that render on every page and are edited in one place, because they are one instance rather than one per page.
Prerequisites
- A template with two pages — Add a page.
- Pages and composition for where instance identity comes from.
Steps
Write the chrome as ordinary sections
Chrome that renders is a section. There is no layout construct to put it in, and a page may hold nothing else:
import { fact, Section, section, Slot, text } from "@homepages/concrete";
export const SiteHeader = section(
{
key: "site-header",
label: "Header",
required: true,
slots: {
wordmark: text.short({ label: "Wordmark", source: fact.property.address.street }),
},
},
({ slot, nav }) => (
<Section>
<header>
<Slot.Text slot={slot.wordmark} as="span" />
<nav>
<ul>
{nav.pages.map((page) => (
<li key={page.id}>
<a href={page.href} aria-current={page.current ? "page" : undefined}>
{page.label}
</a>
</li>
))}
</ul>
</nav>
</header>
</Section>
),
);nav.pages is the site's pages in composition order, already filtered: a page a
user switched off is not in the list, so a menu never has to know that optional
pages exist. current marks the page this render is for.
required: true is what stops a user hiding the chrome — a required section shows
no eye in the editor.
Place the same value on every page
import { fact, fill, Section, section, Slot, text } from "@homepages/concrete";
import type { ReactNode } from "react";
declare const SiteHeader: () => ReactNode;
declare const SiteFooter: () => ReactNode;
const headline = text.medium({
label: "Headline",
cap: 60,
source: fill.write({
reads: [fact.property.description],
brief: "Name 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 Home = () => (
<>
<SiteHeader />
<Hero />
<SiteFooter />
</>
);The details page places the same two values around its own section. That is the whole of it: one section value placed on many pages is one instance, rendered on each. The user edits the wordmark once and every page changes, because there is one content document behind it.
Identity comes from the section's own key — the default instance id is
<key>-1 — so it survives you reordering pages or inserting a section above it.
Only a second placement of the same section on the same site has to say
anything, and it says it with instance:
import { fact, fill, Section, section, Slot, text } from "@homepages/concrete";
const line = text.short({
label: "Line",
cap: 40,
source: fill.write({
reads: [fact.property.description],
brief: "Name what makes the property worth seeing. Write one sentence. Plain and short.",
}),
});
const Banner = section(
{ key: "banner", label: "Banner", slots: { line } },
({ slot }) => (
<Section>
<Slot.Text slot={slot.line} as="p" />
</Section>
),
);
export const Gallery = () => (
<>
<Banner />
<Banner instance="banner-2" />
</>
);Give the fixture one entry, not one per page
A content entry belongs to an instance, so shared chrome takes exactly one entry
however many pages place it — and no instance argument, because there is only
one.
Watch the seams
A section's root carries no margin: zero margin is what lets consecutive sections
butt edge to edge, and a header that pushes itself down with one is
render/section-root-margin. Space the
contents with padding instead.
Verify
In concrete dev, edit the footer on one page and switch canvases: the other page
already has it. Both frames are renders of the same instance.
For the mechanical proof, run concrete build and read
.concrete/build/template/composition.json: the header appears in both pages'
section lists under one instance id.
{ "section": "my-template/site-header", "instance_id": "site-header-1", "required": true }