For developers

4. Blocks

From the THINQ Site developer guide, in the guide's own words. The same text ships with every site's core.

A block is a section of a page: a hero, a row of program cards, a schedule. Editors build pages by adding blocks, filling in their fields and putting them in order. As the template developer, most of your work is writing blocks. This chapter covers how to write one that an editor can actually use.

4.1 The shape of a block

A block is four things:

Piece What it is
Schema A Zod object. It validates the content and generates the editing form
Component A React component that receives { block }, typed from the schema
Definition An entry in your feature's blocks list: type, label, category, defaults
Registration Your feature in src/features/index.ts (done once, for all your blocks)

Content is stored in the page's JSON as an object whose type matches your block:

{ "type": "encoreProgramCards", "title": "Find your stage", "programs": [{ "name": "Dance" }] }

4.2 A complete block, file by file

src/features/encore/schemas.ts

import { z } from "zod";

export const programCardsBlockSchema = z.object({
  type: z.literal("encoreProgramCards"),        // must match the definition's type
  eyebrow: z.string().optional(),
  title: z.string(),
  intro: z.string().optional(),                 // rich text (by name, see §4.3)
  anchor: z.string().regex(/^[a-z0-9-]*$/, "Lowercase letters, digits and hyphens").optional(),
  programs: z
    .array(
      z.object({
        name: z.string(),
        ages: z.string().optional(),
        description: z.string().optional(),     // rich text
        image: z.string().optional(),           // media picker
        linkLabel: z.string().optional(),
        href: z.string().optional(),
        color: z.enum(["magenta", "violet", "gold", "teal"]).optional(),   // a dropdown
      })
    )
    .min(1)
    .describe("One card per program. Colour picks the card's accent."),
});

export type ProgramCardsBlock = z.infer<typeof programCardsBlockSchema>;

src/features/encore/ProgramCards.tsx

import type { ProgramCardsBlock } from "./schemas";
import { SafeHtml } from "@/components/SafeHtml";
import { SiteImage } from "@/components/SiteImage";

const ACCENT = {
  magenta: "border-t-[var(--encore-magenta)]",
  violet: "border-t-[var(--encore-violet)]",
  gold: "border-t-[var(--encore-gold)]",
  teal: "border-t-[var(--encore-teal)]",
} as const;

export function ProgramCards({ block }: { block: ProgramCardsBlock }) {
  return (
    <section id={block.anchor || undefined} className="scroll-mt-24 px-6 py-20">
      <div className="mx-auto max-w-6xl">
        {block.eyebrow ? <p className="eyebrow">{block.eyebrow}</p> : null}
        <h2 className="text-4xl font-semibold">{block.title}</h2>
        {block.intro ? <SafeHtml html={block.intro} className="rich-text-content mt-4" /> : null}

        <ul className="mt-10 grid gap-6 md:grid-cols-3">
          {block.programs.map((p, i) => (
            <li key={i} data-motion-item className={`border-t-4 ${ACCENT[p.color ?? "magenta"]} bg-ink-soft p-6`}>
              {p.image ? (
                <SiteImage src={p.image} alt="" sizes="(min-width: 768px) 33vw, 100vw" className="aspect-[4/3] w-full object-cover" />
              ) : null}
              <h3 className="mt-4 text-xl font-semibold">{p.name}</h3>
              {p.ages ? <p className="text-sm text-cream-dim">{p.ages}</p> : null}
              {p.description ? <SafeHtml html={p.description} className="rich-text-content mt-3" /> : null}
              {p.href ? <a href={p.href} className="mt-4 inline-block font-semibold text-sunset-2">{p.linkLabel || "Learn more"}</a> : null}
            </li>
          ))}
        </ul>
      </div>
    </section>
  );
}

src/features/encore/index.ts

import type { FeatureModule } from "@/framework/feature-module";
import { programCardsBlockSchema } from "./schemas";
import { ProgramCards } from "./ProgramCards";
import { EncoreHeader } from "./Header";
import { EncoreFooter } from "./Footer";

export const encoreFeature: FeatureModule = {
  id: "encore",
  name: "Encore Performing Arts",
  description: "Encore's own sections.",
  version: "1.0.0",
  adminSections: [],
  chrome: { header: EncoreHeader, footer: EncoreFooter },
  blocks: [
    {
      type: "encoreProgramCards",
      label: "Program Cards",
      category: "Custom",
      description: "A row of class or program cards, each with its own colour, ages and a link.",
      schema: programCardsBlockSchema,
      component: ProgramCards,
      defaultValue: { type: "encoreProgramCards", title: "", programs: [{ name: "" }] },
      sample: {
        type: "encoreProgramCards",
        eyebrow: "Classes",
        title: "Find your stage",
        programs: [
          { name: "Dance", ages: "Ages 3 to adult", color: "magenta" },
          { name: "Voice", ages: "Ages 6 and up", color: "violet" },
        ],
      },
    },
  ],
};

Then register encoreFeature once in src/features/index.ts (§2.6). The block is now in Add block → Custom, in the block catalogue at /admin/blocks, in page validation and in the renderer. There is no second place to register anything. If you find yourself adding a switch to BlockRenderer, the registration step was missed.

The definition, field by field

From core/src/framework/feature-module.ts:

Field Required What it does
type yes Unique id, the same as the schema's z.literal(...). Prefix it with your site (encoreProgramCards) so it can never collide with a core block
label yes The name in the Add menu. Plain words, not camelCase
category yes Add-menu group: Layout, Content, Media, Marketing, Forms or Custom
schema yes The Zod object
component yes ({ block }) => JSX
defaultValue yes What a newly added block starts with. Usually empty fields, and at least one item in any required list
sample no Realistic content for the block catalogue. Falls back to defaultValue, which usually previews as a blank section
description no One plain sentence for the catalogue: what the section is and when to use it. Client-facing
setupNote no A warning shown where the block is picked, for blocks that need something outside the site first (an API key, a vendor account)
adminOnly no Only admins can add or edit it; enforced by the server on save. Required for any block that renders raw HTML or script
motionParts no Separately animatable pieces of the block (§4.9)

4.3 Field names choose the editor

The admin builds the editing form from your schema. Each field's type picks the kind of input, and for strings, the field's name picks which editor. This is the rule that surprises people most, so it is worth learning by heart. From core/src/lib/zod-form-fields.ts:

Field name Editor What it stores Render with
body, description, intro, subtitle, quote, challenge, solution Rich-text editor HTML (<p>…</p>) <SafeHtml html={…} />
line, or any name ending in Body (cardBody) Multi-line plain text Text {text} (use whitespace-pre-line to keep line breaks)
html, css, markup, or ending in Html / Css Tall monospace code box Raw markup Depends; see Embeds
image, src, photo, logo, poster, thumbnail, background, icon, favicon, mediaPath, publicPath, or ending in Image, Src, Icon, Poster, Logo, Photo, Thumbnail, Background, MediaPath, PublicPath Media picker (the Media library) A path like /media/photo.jpg, or a URL <SiteImage src={…} alt="…" />
formId Form picker (a list of the site's forms) A form id The forms feature (Header §5.9)
A list of strings named recap, answer or bio (or any rich-text name) A list of rich-text editors HTML in each <SafeHtml> for each
Anything else One-line text input Text {text}

Rich-text editors are only used for those seven names on a multi-line field, so a field called bio on its own is a one-line input. If you want rich text, use one of the seven names. If you want plain text that wraps, end the name in Body.

The most common bug: a field named description rendered as {p.description}. The editor saved <p>Ballet and tap</p>, so visitors see the tags. Render rich-text fields with SafeHtml, always:

<SafeHtml html={p.description} className="rich-text-content" />

SafeHtml sanitizes with DOMPurify (scripts, styles and forms are removed) and renders a div by default; as="span" | "p" | "blockquote" | "figcaption" changes the element. The rich-text-content class gives paragraphs, lists and links their spacing.

A test, core/src/components/blocks/rich-text-render.test.ts, fills every rich-text field of every registered block with HTML and fails if any of it comes out escaped. For your site's blocks it reports a TODO instead of failing, so one site's bug can't hold up core updates for everyone. A TODO line in your test output is a real bug in your block. Fix it.

4.4 Field types and their inputs

Zod Input
z.string() Text input (or one of the editors above, by name)
z.number() Number input
z.boolean() Checkbox
z.enum([...]) Dropdown of the values (shown as written, so use readable values: "left", "right")
z.object({...}) A nested group of fields
z.array(z.string()) A list of text inputs with add and remove
z.array(z.object({...})) A repeatable group: add, remove and reorder (↑ ↓) items, each with its own fields
z.discriminatedUnion("kind", [...]) A choice of types: a dropdown of the types, then only the chosen type's fields. In a z.array(...), each item has its own type and Add offers the types. .describe("Heading") on each option names it in the menu
.optional() / .nullable() Marked optional in the editor, can be left empty, and left out of new items
.default(x) Filled with x when missing
z.literal("…") Not editable (used for type)

Fields appear in the order you declare them, labelled from the name (linkLabel shows as "Link Label"), so name fields the way an editor would say them. Other Zod types (plain unions without a discriminator, records, dates) have no input and don't appear in the editor, so keep block schemas to the types above.

An object field named styling is folded away under "Styling (advanced)". Put the values the design keys on but an editor should never need there: class names and ids carried over from a ported site, a widget's original attributes. They are still saved and still validated; the editor just doesn't see them unless they open the group.

const item = z.discriminatedUnion("kind", [
  z.object({ kind: z.literal("heading"), title: z.string(), styling: z.object({ cls: z.string() }) }).describe("Heading"),
  z.object({ kind: z.literal("text"), body: z.string(), styling: z.object({ cls: z.string() }) }).describe("Text"),
  z.object({ kind: z.literal("image"), image: z.string(), alt: z.string() }).describe("Image"),
]);
// items: z.array(item)  → Add ▾ Heading / Text / Image; each item shows its own fields

This is how a page ported from a page builder (Elementor, WPBakery) stays editable: every widget becomes a typed item whose copy is in fields, its builder classes in styling, and the component prints the builder's markup around the fields so the ported stylesheet still applies. Don't store a widget as one html field; an editor can't use it.

.describe("…") on an array shows that text under the group's heading in the editor. Use it to explain what the items are and where values come from ("Latitude and longitude from Google Maps: right-click the pin").

z.string() accepts an empty string. If a field must be filled in, say so with .min(1, "Add a title"). Then the save is refused with your message until it is.

4.5 What validation does, and why it matters for you

  • On save, the admin validates the whole page against every registered block schema. Content that does not match is refused with the field named, so a half-filled section never reaches a visitor.
  • Anything not in the schema is dropped. Zod removes unknown keys. If your component reads block.subtitle but the schema has no subtitle, it will always be empty, and a value put in the JSON by hand disappears on the next save.
  • On render, the page is validated again. A page whose content no longer matches is treated as missing: the public URL returns 404 and the server logs [mypress] invalid page <slug>: <field>: <problem>.

That last point means a schema change can take live pages down. Pages on staging and the live site were saved against your old schema. Change it safely:

Change Safe?
Add an .optional() field, or one with .default() Yes
Add a required field No. Every existing block lacks it, so every page using the block goes 404. Make it optional, or give it a default
Rename or remove a field Removing is safe (the old value is dropped on next save). Renaming loses the old values: add the new field as optional and read both for a while
Remove an enum value that content uses No. Pages using that value go 404
Tighten a rule (.min(1), a regex) Only if all existing content already passes
Rename the block's type No. Every existing block of the old type no longer matches anything

Before you merge a schema change, check staging's pages with it: open each page that uses the block in /preview/<slug>, or ask Bo to check the live content against the new schema.

4.6 Components: server, client, and what they may import

  • A block component is a React Server Component by default: it renders on the server, and its HTML is cached. That is right for almost every section.
  • Add "use client" at the top when the block needs state or browser APIs (a carousel, tabs, an accordion). Keep the interactive part small: a server component for the section that renders a small client component for the moving part.
  • Block components must not import server-only code (node:fs, @/lib/content, anything that reads files). The feature registry is also loaded in the browser by the admin's page builder and block catalogue, so a server-only import in a block breaks the admin build. A block that needs live data fetches it in a client component from an API route; that is how core's Form and Event Tickets blocks work.
  • Use SiteImage for images, not <img> or next/image. It lazy-loads by default, fills in width and height for uploaded images so the page doesn't jump, and with sizes serves smaller versions to phones. alt is required ("" for decorative images); pass priority for an image at the top of the page.
<SiteImage src={block.image} alt={block.title} sizes="(min-width: 1024px) 50vw, 100vw" className="w-full" />

Editors type links as text, so be generous in what you accept and careful in how you render:

  • Site pages are paths: /classes, /tour/dallas. Sections on the same page are #programs; sections on another page are /classes#programs.
  • Prefer real page paths over #anchors for navigation. An anchor link from another page only works if it includes the path (/#about, not #about).
  • Render with a plain <a href>. Core rewrites links inside /preview so they stay in preview.

To let a #link jump to a section, give the block an anchor field and put it on the section's id:

anchor: z.string().regex(/^[a-z0-9-]*$/, "Lowercase letters, digits and hyphens").optional(),
<section id={block.anchor || undefined} className="scroll-mt-24 …">

The editor fills in programs, and a link to #programs (or /classes#programs from another page) jumps there. Smooth scrolling handles the jump, and it honours scroll-margin-top, so scroll-mt-24 (96px) stops the section landing under a sticky header. Match it to your header's height.

Verified on 2026-10-21 in a production build of the Encore site: clicking #programs scrolled the section to exactly 96px from the top.

Core's own blocks don't have an editable anchor. A few have a fixed one (#services, #about, #process, #case-studies, #contact on the CTA section, and #form-<id> on a Form block), which is where the sample site's jump links pointed. An anchor setting on every block, core's included, is on the open list in CHANGELOG.

4.9 Entrance motion

Every block, yours included, gets an editable Motion panel (effect, delay, duration, stagger) with no work from you. To make it animate well:

  • Mark the items that should stagger with data-motion-item (cards, list items).
  • Declare motionParts for pieces that should animate on their own (a photo over its backdrop), and spread motionPartProps(block, "photo") from @/lib/motion on them.

The details, and porting Elementor animations, are in docs/motion.md.

4.10 Testing a block

  1. Open /admin/blocks: your block is listed with its sample. Check it looks right with realistic content, and with the empty defaultValue.
  2. Add it to a page in the admin, fill in every field, save, and open the page with Preview. Then empty the optional fields and check nothing breaks.
  3. Put HTML (bold, a list, a link) in every rich-text field and check it renders.
  4. Run the tests and the production build on the assembled tree (Testing §8.4). Look for TODO lines naming your block.

4.11 Changing a core block

The built-in blocks (Hero, Services, Pricing, Columns, FAQ, Team, Gallery and the rest: see /admin/blocks) belong to core, so they can't be edited per site. You have three options, in order of preference:

  1. Restyle it with tokens. Core blocks take every colour from the theme's core tokens (Themes §3.3) and their font from --font-display. Often that is enough.

  2. Copy it into your feature as a new block. When you want to move things around, change markup or add fields:

    • copy the component from core/src/components/blocks/<Name>.tsx into src/features/<yours>/;
    • copy its schema from core/src/lib/schemas.ts into your schemas.ts, and change the literal to a new type (hero → encoreHero);
    • register it with a new label ("Hero — Encore").

    Your copy is yours from then on. It won't receive core's later fixes to the original, and existing pages keep using the core block until an editor swaps it out.

  3. Ask for an option on the core block. If the change would suit other sites too (an image position, a background choice), it may belong in core as a setting. Ask Bo.

What not to do:

  • Don't put a file at src/components/blocks/<Name>.tsx in your repo. It replaces core's component without any warning, and cuts it off from fixes (see §2.5).
  • Don't register a block with a core block's type (hero, columns). Every type must be unique; reusing one breaks validation for every page.

4.12 Block checklist

  • type prefixed with your site name, the same in the schema and the definition
  • Rich-text field names rendered with SafeHtml
  • Images through SiteImage with real alt text, sizes on large images
  • Optional fields render nothing (not an empty heading) when empty
  • defaultValue valid against the schema (a required list has one item)
  • sample realistic enough for the catalogue, description written for an editor
  • anchor field if editors will link to it
  • No server-only imports in the component
  • adminOnly: true if it renders raw HTML or script
  • Schema change checked against content already on staging (§4.5)

This text is maintained in thinq-site-core at docs/developers/04-blocks.md (commit e72488e) and published here unchanged.