Concrete
GuidesCompose a template

Follow another section's value

Two sections have to agree — a footer echoing the hero, a gate printing the property's name — so one slot mirrors or derives from the other.

Goal

Make a value in one section follow a value in another, by declaring the read on the slot that depends rather than in either renderer.

Prerequisites

The workspace from Start and two sections placed on a page. Read Reading another section first: it says why a renderer may not reach across sections, which is the constraint this recipe is shaped by.

Steps

1. Mirror the slot that should hold the same value

A slot whose value IS another section's names that slot as its source:. The ref comes off the section value (Hero.slots.headline), never off an instance — a slot is written without knowing how the template composes.

template.ts
import { defineTemplate, fact, fill, Section, section, Slot, text, website } from "@homepages/concrete";

import icon from "./icon.svg";

const Hero = section(
  {
    key: "hero",
    label: "Hero",
    slots: {
      headline: text.medium({
        label: "Headline",
        cap: 80,
        source: fill.write({ reads: [fact.property.description], brief: "Name what makes the property worth seeing. Write one sentence. Confident and short." }),
      }),
    },
  },
  ({ slot }) => (
    <Section>
      <Slot.Text slot={slot.headline} as="h1" />
    </Section>
  ),
);

const Footer = section(
  {
    key: "footer",
    label: "Footer",
    slots: { tagline: text.medium({ label: "Tagline", cap: 80, source: Hero.slots.headline }) },
  },
  ({ slot }) => (
    <Section as="footer">
      <Slot.Text slot={slot.tagline} as="p" />
    </Section>
  ),
);

const Home = () => (
  <>
    <Hero />
    <Footer />
  </>
);

export default defineTemplate({
  key: "riverside",
  name: "Riverside",
  format: website,
  icon,
  scope: "global",
  pages: { home: { label: "Home", path: "/", page: Home } },
});

The mirror holds the same kind of value as its upstream — a text slot mirrors a text slot — or concrete check refuses it at relations/mirror-type. A mirror holds no value of its own, so a user's edit to the footer's tagline edits the hero's headline (where an edit goes). A projection, a join, or a line seeded from the headline but free to differ is a derivation, the next step.

A list follows another section's list the same way: its source: is that list, and it holds that list's elements in that list's order. A pick of comparables made once, in one section, is then shown by a second, each item reading its row:

sections/rivals.ts
import { fact, fill, list, number, object, row, section } from "@homepages/concrete";

const Comparables = section(
  {
    key: "comparables",
    label: "Comparables",
    slots: {
      selected: list({
        label: "Shown comparables",
        max: 8,
        source: fill.pick({ brief: "The nearest sold comparables, closest first." }),
        item: row({ label: "Comparable", from: fact.property.comparables }),
      }),
    },
  },
  () => null,
);

const rivals = list({
  label: "Competing listings",
  source: Comparables.slots.selected,
  item: (el) => {
    const comp = row({ label: "Comparable", from: fact.property.comparables, source: el, locked: true });
    return object({
      label: comp.address.street,
      fields: { comp, price: number({ label: "Price", source: comp.price }) },
    });
  },
});

A row follows another section's row the same way, which is how a page names one agent everywhere. Keep the row the user re-picks in an object — the hero's agent card, whose bar the editor shows — and mirror it through that object's field ref: row({ label: "Agent", from: fact.property.contacts, source: Hero.slots.agent.fields.contact, locked: true }).

The mirror is locked because the agent is re-picked in the hero's card, never here; a re-pick there moves every mirror, and each section reads the mirror's members as it would its own row's.

2. Derive when the value is a function of the other

compute({ reads }, fn) takes the other section's slot beside any facts, and hands the callback one value per ref, in order. A slot value is | undefined — the upstream may be empty or unplaced — so the body decides the fallback:

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

const Hero = section(
  {
    key: "hero",
    label: "Hero",
    slots: {
      headline: text.medium({
        label: "Headline",
        cap: 80,
        source: fill.write({ reads: [fact.property.description], brief: "Name what makes the property worth seeing. Write one sentence. Confident and short." }),
      }),
    },
  },
  ({ slot }) => (
    <Section>
      <Slot.Text slot={slot.headline} as="h1" />
    </Section>
  ),
);

export const footerLine = (headline: string | undefined, city: string | null): string => headline ?? city ?? "";

export const Footer = section(
  {
    key: "footer",
    label: "Footer",
    slots: {
      tagline: text.medium({
        label: "Tagline",
        cap: 80,
        source: compute({ reads: [Hero.slots.headline, fact.property.address.city] }, footerLine),
      }),
    },
  },
  ({ slot }) => (
    <Section as="footer">
      <Slot.Text slot={slot.tagline} as="p" />
    </Section>
  ),
);

Naming the derivation and exporting it keeps it reachable from a test.

3. Read a sibling through its own const

Inside one section, hoist the upstream slot to a const and name it — Section.slots.* does not exist until the section is declared:

sections/hero/section.tsx
import { compute, fact, fill, text } from "@homepages/concrete";

const headline = text.medium({
  label: "Headline",
  cap: 80,
  source: fill.write({ reads: [fact.property.description], brief: "Name what makes the property worth seeing. Write one sentence. Confident and short." }),
});

const eyebrow = text.short({
  label: "Eyebrow",
  cap: 80,
  source: compute({ reads: [headline] }, (value) => value?.toUpperCase() ?? ""),
});

4. Keep the graph a DAG, and every read placed

Two sections that read each other are a loop — relations/section-cycle — and a read of a section no page places resolves to nothing — relations/unplaced-read. Add the read and the placement in the same change. A fill may not read a mirrored or derived slot: those settle after every fill has run (relations/fill-reads-computed).

The callback compiles into the section's logic bundle, which carries no React — reaching a component or a hook through it fails logic/section-build-failed.

Verify

Run concrete dev, edit the hero headline in the playground and watch the footer follow it. Edit the mirrored tagline of step 1 and the hero's headline changes with it. Edit the derived tagline of step 2 instead and it keeps your value: later edits to the headline no longer move it until you clear the override. Run concrete check: the relations stage resolves every read to a placed instance.

On this page