section
Looking up what a section declares, what its render receives, and how the platform finds it.
section
Signature
import { fact, fill, Section, section, Slot, text } from "@homepages/concrete";
export const Hero = section(
{
key: "hero",
label: "Hero",
slots: {
headline: text.medium({
label: "Headline",
cap: 60,
source: fill.write({
reads: [fact.property.address, fact.property.description],
brief: "A marketing headline for the property. Write one sentence. Confident, no exclamation marks.",
}),
}),
},
},
({ slot, nav }) => (
<Section id={nav.selfAnchor}>
<Slot.Text slot={slot.headline} as="h1" />
</Section>
),
);Parameters
The first argument declares the section.
key is the platform identity: its key in the catalog, its in-page fragment, and
the stem of the default instance id (<key>-1). label is the section's name in
the editor. required makes the section required wherever it is placed, and
defaults to false. slots is the slot declarations, in editor order.
display is the section's visibility and variant axes, each an optional
select({ from, source }) entry.
The second argument is the render function, which receives bindings rather than raw values.
slot holds one binding per declared slot, keyed by slot id and typed by that
slot's own declaration. nav is the build-injected navigation input — selfAnchor
is this section's own id, anchors maps a target section key to a resolved href,
and pages is the site's pages in composition order with current marking this
one. variant is the stored variant case, typed as the union of the declared
cases, and a plain string when the section declares none.
The returned value is also the component a page places, which takes one optional
prop: instance, the instance id when a template places the section more than
once.
Constraints
Always an explicit key, never one derived from the export or the file name.
Renaming a variable must not mint a new section and orphan its content.
Always export the value. Discovery reads the exports of every module, so a section a page places but no module exports cannot be bundled on its own.
Always a unique key across the workspace: two exported sections declaring one key fail the workspace stage.
Always one section per exported value, and the same value on every page that
places it — one section, many instances. A second placement takes its own
instance.
Always one origin on every declared value slot — a source:, whether a fact, a
row's member, a slot ref, a compute() or a fill (fill.write, fill.pick,
fill.find) — and on every field of an object(), where the item's element is
an origin too. A slot with none is sections/schema-invalid: nothing would ever
write it. An object() holds no value of its own and takes no source; a list's
item takes its elements from the list's source; and a standalone poi with no
source is exempt, which the editor picks.
Never read a value off a raw slots object; read it through the binding slot
hands you. The binding is what carries the marker the editor selects by.
Never emit a data-slot-* attribute yourself. The slot primitives emit the
markers, and a hand-written one is refused.
Never a group declared beside the slots. Slots edited as one card are the fields
of one object() in slots, rendered inside its Slot.Object; a field belongs
to that object and no other, and one marked outside it fails the render stage.
Never render a section bare: it renders through the platform, a fixture, or a probe. Called with no slot values it throws, naming itself.
Never a clock, a random source, or any browser-side work in the render. It is a pure function of the bindings it is handed; anything interactive is an island.
Example
import { compute, fact, fill, image, object, Section, section, Slot, text } from "@homepages/concrete";
export const Listing = section(
{
key: "listing",
label: "Listing",
required: true,
slots: {
photo: image({
label: "Hero photo",
crop: { mode: "locked", aspect: 3 / 2 },
from: fact.property.property_media,
source: fill.pick({ brief: "The photo that best shows the front of the property." }),
}),
address: object({
label: compute(() => "Property address"),
fields: {
street: text.short({ label: "Street", source: fact.property.address.street }),
locality: text.short({ label: "City", source: fact.property.address.city }),
},
}),
},
},
({ slot, nav }) => (
<Section id={nav.selfAnchor}>
<Slot.Image slot={slot.photo} />
<Slot.Object slot={slot.address} as="address">
<Slot.Text slot={slot.address.street} as="span" />
<Slot.Text slot={slot.address.locality} as="span" />
</Slot.Object>
<a href={nav.anchors.gallery}>See every photo</a>
</Section>
),
);Rules that apply
workspace/duplicate-section-key,
pages/section-not-exported,
sections/schema-invalid,
slots/no-raw-values,
slots/no-marker-literal,
render/missing-slot-marker,
render/group-ancestry,
server/no-nondeterminism.
See also
slot builders for what a section may expose,
template.ts for the pages that place one, and
Sections for why identity is explicit, and
Server and client for why a renderer is pure.
