Concrete
GuidesCompose a template

Add a page

One page is not enough — the listing needs a gallery, a neighbourhood page, a floor-plan page of its own.

Goal

A second page in the template, with its own section, its own path, and a place in the navigation every other section reads.

Prerequisites

  • The workspace Start leaves you with.
  • Pages and composition for why a page is read once by a probe rather than rendered like a component.

Steps

Write the section it will place

A page places sections and nothing else, so a new page needs at least one:

sections/details.tsx
import { fact, fill, Section, section, Slot, text } from "@homepages/concrete";

export const Details = section(
  {
    key: "details",
    label: "Details",
    slots: {
      heading: text.medium({
        label: "Heading",
        cap: 60,
        source: fill.write({
          reads: [fact.property.address],
          brief: "Name what this page covers, in under 60 characters. Write one sentence. Plain.",
        }),
      }),
    },
  },
  ({ slot, nav }) => (
    <Section id={nav.selfAnchor}>
      <Slot.Text slot={slot.heading} as="h1" />
    </Section>
  ),
);

Export it. Discovery reads the exports of every module, and a section a page places but nothing exports cannot be bundled on its own — pages/section-not-exported.

Write the page

A page component takes no props and returns sections. A fragment is fine, and so is a wrapper component of your own, as long as what it finally contains is sections:

pages/details.tsx
import type { ReactNode } from "react";

// import { Details } from "@/sections/details";
declare const Details: () => ReactNode;

export const DetailsPage = () => <Details />;

A host element here — a wrapping div, a stray string — is pages/non-section-markup, named at the page's own module: the probe found markup left over after the sections recorded themselves, and the platform has nowhere to put it. Chrome that renders is a section, not page markup.

Declare it

template.ts
import { defineTemplate, website, type PageComponent } from "@homepages/concrete";
import icon from "./icon.svg";

declare const Home: PageComponent;
declare const DetailsPage: PageComponent;

export default defineTemplate({
  key: "my-template",
  name: "My Template",
  format: website,
  icon,
  scope: "global",
  pages: {
    home: { label: "Home", path: "/", page: Home },
    details: { label: "Details", path: "/details", page: DetailsPage, optional: true },
  },
});

The object key is the page id and the object order is the order the artifact carries. label is the name in the editor's page bar and in a nav menu; path is one lowercase-kebab segment, with exactly one page on "/".

optional: true lets a user switch the whole page off: it then publishes nothing and drops out of the navigation. The root page can never be optional, because a site has to answer /.

Nothing needs a URL written by hand. A section reaches another section through nav.anchors, which resolves to a bare fragment on the same page and to the other page's URL plus the fragment across pages — the same code either way:

import { fact, fill, Section, section, Slot, text } from "@homepages/concrete";

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.",
  }),
});

export const Hero = section(
  { key: "hero", label: "Hero", slots: { headline } },
  ({ slot, nav }) => {
    const details = nav.anchors.details;
    return (
      <Section id={nav.selfAnchor}>
        <Slot.Text slot={slot.headline} as="h1" />
        {details === undefined ? null : <a href={details}>See the details</a>}
      </Section>
    );
  },
);

The guard is the point on an optional page. A target reachable only through a page the user has switched off is absent from the map rather than resolving to a page that publishes nothing — and absence is the renderer's signal to omit the control, because an href-less anchor is a dead one.

For a menu over the whole site, read nav.pages — every page in composition order, with the hidden ones already dropped. That is what a shared header is built from.

Verify

concrete dev grows a second canvas: the canvas bar switches between them, and the new page is editable there like the first. If the page is optional, its frame carries an eye that hides it — hide it and the hero's link goes with it, because navigation is resolved over the same display state.

concrete check then renders both pages under the probe. The composition it derives is written to .concrete/build/template/composition.json by concrete build, which is the file to read when you want to see exactly which instances your pages produced.

On this page