Page editor

Add a new section block to the page editor

A hand sketching page wireframes beside a laptop

Overview

Every section on this site, from the hero to the footer, is a block in the page editor. A block is a React component whose text, links and images live in its props, so editors can change them without touching code.

The server stores only blocks it knows by name and checks every link and image in their props before it saves a page.

Name it

Add the block's name to siteBlockNames in packages/contracts/src/site.ts. The API refuses a page that uses a name missing from this list.

Write the component

Create the component in apps/web/src/features/site/blocks and wrap it with defineBlock. Render text with EText, links with ELink and images with EImage, each pointing at a prop by its path, and list the fields the Style panel shows for it.

Lay it out with the page container's breakpoints, @max-[1280px]/page and @max-[810px]/page, so it follows the editor's tablet and phone frames as well as the browser.

  1. Add the name to siteBlockNames
  2. Write the component with defineBlock
  3. Register it in the blocks' index.ts
  4. Give it starting content in a template page
Hands sketching page layouts beside a laptop
A person arranging sticky notes on a wall

Register it

Add the block to the index.ts beside it so the editor and the public renderer can resolve it. The Insert tab starts a new block with the content it has in the site template, so add it to a page in packages/contracts/src/site-template as well.

Install the template again from Admin, Pages. Pages you have already edited keep your changes.

0

Places to change: the name, the component, the index and the template.

0

Frames to check it in: desktop, tablet and phone.

0

Blocks a single page can hold before the server refuses to save it.

You might also like

Billing
A woman typing on a laptop at a desk by a window

Add a plan and change what each plan includes

Edit the plans in the contracts package, create the Stripe price and check the limits on the server.

Deploy
A woman on a phone call by an office window

Deploy the starter to Railway in one click

Postgres, the API and the web proxy on one private network, with migrations run before each deploy.

A woman pinning shapes to a glass wall

Let's Talk

Get in touch