Page Builder
Let your team compose pages from blocks you define. Pages render on the server, and the core blocks add no JavaScript of their own.
The Page Builder gives non-developers a canvas. They drag blocks onto a page, arrange them, set text and images, and publish. You decide which blocks exist.
That split is the point. Your developers decide what is possible; your team decides what goes on the page. Someone editing a page cannot invent a new kind of section, so a site cannot drift away from its design system by accident.
It ships as a plugin, @nextlyhq/plugin-page-builder.
What you get
- 23 blocks out of the box. Layout (section, box, columns, column, card, accordion, question, spacer, divider), content (heading, paragraph, rich text, table of contents, list, quote, image, gallery, icon, button, embed, form), one that reads from your content (Collection list), and Entry content, offered only in a collection's template, where it draws the entry's own blocks.
- Icons. The Icon block draws one icon from the built-in Lucide
set as inline SVG, rendered on the server, so a published page ships no script for it.
Its Icon control (Content tab) opens a search-first picker that offers the icons you
used last first. It is sized by its font size and drawn in its text colour (Style tab).
Leave Screen reader label empty for a decorative icon, which screen readers skip;
fill it in for an icon that says something on its own. A linked icon is named by its
label, or by the icon's name when there is none. The page stores the icon's id
(
lucide:star); an id the set no longer draws renders nothing, and the editor says so. - Accordions. A new accordion starts with three questions, "Question 1" to
"Question 3", each with a Text answer to write over. While the accordion or one of its
questions is selected, + Add a question under the last one adds the next numbered
question, opens it and puts the cursor in its title, which you type on the canvas. A
question's answer holds any blocks: a picture, a button, a list. Its Arrange (Style
→ Layout) lays them out as a container's does: set to Row, they sit side by side
under the title. They're held in the question's body,
.nx-bp-core--accordion-item--body, which a stylesheet of your own reaches them through. In its Content tab, Behaviour has Open (One at a time, the default, where opening one question closes the others, or Many), First open (on by default) and Titles as (plain text or a heading from level 2 to 6, Heading 3 by default), and Icon picks + / −, Chevron or None; Icon position (Style tab) puts it before or after the title. A question's Open by default shows only with Many. Each question is a native<details>, so it opens and closes by mouse, touch or keyboard (Enter, Space) with no script, and One at a time is the browser's own grouping too. Each title row is at least 44px tall, shows a focus ring from the keyboard, and its icon is hidden from screen readers. An accordion saved before these settings opens each question by its own setting, as Many does. Some screen readers announce a question's title as the button's text rather than as a heading; it still opens and closes as normal. - Columns, sections and linked containers. A Columns block picks its columns in its Content tab: 2 equal, 3 equal, 4 equal, Wide left, Wide right or Wide middle, adding or removing empty columns to match, and Stack on puts the columns one under another on tablets and phones, on phones only, or never. A Section's Min height (Style tab, Size) has a Full screen button. A Box or a Card can link as a whole to a page on this site or to an address, opening in a new tab if you choose; its link relationship is under Advanced, HTML.
- Your own blocks, defined in code, which the page renderer takes beside the built-in ones.
- Per-breakpoint styling. Style a block separately for each breakpoint: the Style tab edits the breakpoint the canvas is sized to, and the canvas resizes to each breakpoint's width. See Breakpoints.
- Server rendering. Pages render on the server, and the core blocks add no JavaScript of their own. Every page still loads the Next.js runtime, and a block you write as a client component sends its own JavaScript. See What reaches the browser.
Availability
| Package | @nextlyhq/plugin-page-builder, plus @nextlyhq/blocks-react in your app |
| Status | Alpha. The block model, the registries, the render pipeline and the editor can all still change |
| Permission | Editing a page requires update access to the collection holding it |
Its collections (pages, headers & footers, saved sections, components, templates and its
own records) are open to the built-in Admin, Editor, Author and Viewer roles, each by its own
rule (an Author does not publish or delete, a Viewer reads);
presetGrants
in the config changes that.
Install
pnpm add @nextlyhq/plugin-page-builder @nextlyhq/blocks-react \
@nextlyhq/builder @nextlyhq/plugin-sdk react-hook-formAdd the plugin to your config. It contributes a pages collection whose edit screen is
the builder:
import { pageBuilder } from "@nextlyhq/plugin-page-builder";
import { defineConfig } from "nextly";
export default defineConfig({
plugins: [pageBuilder()],
});Then install the plugin on your database. Nextly installs plugins explicitly, so a plugin that is configured but not installed only gets a warning in development, and a production boot refuses to start:
npx nextly plugins install @nextlyhq/plugin-page-builderThe plugin keeps its usage counts in tables of its own: which documents place each
component and apply each shared style (page_builder__component_usage and
page_builder__class_usage), and the bookkeeping behind them, how far the background
job has indexed existing content and whether an index write has failed
(page_builder__usage_runs and page_builder__usage_progress). No admin screen or
API reaches them. The counts cover collection entries and Singles, and a component a
placement chooses through one of its fields counts as used where it is placed.
Installing creates the tables; a site upgrading from a version without them runs
npx nextly migrate before it starts on the new version, since a production boot
refuses a plugin whose tables are behind it. After the upgrade the background job
indexes every page and Single again, and until it has finished, counts read as "at
least" rather than as exact.
Last, run npx nextly generate:types. It writes the file that registers the builder's
screen with the admin. The builder fetches its own stylesheet when one of its screens or
fields opens, so there is nothing to import by hand. In a project created before that file
existed, import the generated file in your admin page,
src/app/admin/[[...params]]/page.tsx; see Admin UI.
If your admin page still imports @nextlyhq/plugin-page-builder/styles/editor.css by hand,
remove the import. The builder keeps working with it, but the import puts the editor's
stylesheet on every admin screen, the sign-in page included, instead of only where the
builder opens.
In the admin
The Page Builder has its own item in the admin's rail, right after Forms (after Media on a site without the form builder). Its panel lists the libraries pages are built from, each with how many you can see: Saved sections, Components, Header & footer and Collection templates. Under Checks, Connected fields to fix shows a badge while any connected field needs fixing.
Clicking the item opens the Page Builder overview
(/admin/plugins/nextlyhq-plugin-page-builder/overview):
- Connected fields to fix, first, only while there are any, with Review to open the site-wide list.
- The four libraries, each with its count and, if you may create there, a New action that opens its create page.
- Where it is used: the collections and Singles that have a Page Builder field, each opening its list or, for a Single, its edit page. Only those you can read are listed. Add one to a collection or Single in the Schema Builder (choose Blocks) or in code, and it is listed here.
The overview is for people who can edit pages. Anyone else opening the item lands on the
first library they can read. To keep the Page Builder under Plugins instead, set its
placement in admin.pluginOverrides:
import { defineConfig } from "nextly";
export default defineConfig({
admin: {
pluginOverrides: {
"nextlyhq-plugin-page-builder": { placement: "plugins" },
},
},
});Render the pages
A plugin cannot add routes to your Next.js app, so you declare one catch-all route and
let createPublicBlocksPage fill it. It resolves the incoming path against your
collections, 404s on a miss, and renders the stored document. Each published page is
built ahead of time and served from the cache, and publishing or unpublishing it, or
anything it is drawn from, refreshes it.
// src/app/(frontend)/[...slug]/page.tsx
import { createPublicBlocksPage } from "@nextlyhq/blocks-react/next";
import { getNextly } from "nextly";
import type {
NextlyContentReader,
PublicSiteSettingsSource,
} from "nextly/runtime";
import nextlyConfig from "../../../../nextly.config";
type NextlyInstance = Awaited<ReturnType<typeof getNextly>>;
const instance = () => getNextly({ config: nextlyConfig });
// Annotated rather than inferred: without a contextual type these `args`
// parameters are implicitly `any`, which fails `next build` under strict mode.
const reader: NextlyContentReader &
PublicSiteSettingsSource & {
media: Pick<NextlyInstance["media"], "findByID">;
} = {
find: async args => (await instance()).find(args),
findByID: async args => (await instance()).findByID(args),
// The site's name, address, logo and time zone a page shows, read from this
// instance. Omit it and the page shows the settings of the process's
// registered instance, and the route warns once.
publicSiteSettings: async () => (await instance()).publicSiteSettings(),
// Images that store a media id resolve through this. Omit it and those images
// render nothing, while images holding a literal URL keep working.
media: {
findByID: async args => (await instance()).media.findByID(args),
},
};
const route = createPublicBlocksPage({
collections: ["pages"],
field: "content",
nextly: reader,
styleContext: {
breakpoints: {
viewport: [
{ id: "base", label: "Base" },
{ id: "tablet", label: "Tablet", maxWidth: 1024 },
{ id: "mobile", label: "Mobile", maxWidth: 640 },
],
container: [],
},
},
});
export async function generateStaticParams() {
const params = await route.generateStaticParams();
// Until a page is published, build one path that answers not found:
// Next.js refuses an empty list when Cache Components is on.
return params.length > 0 ? params : [{ slug: ["not-found"] }];
}
export const { generateMetadata } = route;
export default route.ContentPage;The breakpoints are optional. A site that states none, here or in the editor, is drawn at the built-in Tablet (1024px) and Mobile (640px) sizes, on the canvas and on published pages alike. A set you state replaces them whole.
The route draws the blocks your site registered, the core set and every block a plugin adds,
custom ones included, with nothing passed: it reads them from the page builder of the site the
process serves. A visitor reaching a page before anyone has opened the admin sees the same
blocks. To draw a page with a set of your own, pass it as blocks
(createBlockResolver([...coreBlocks, myBlock]) from @nextlyhq/blocks-react); a resolver
passed there is always the one used.
Images sized to where they appear
The imageCopies route option and pageBuilderImageCopies() are
experimental: their names and shape may change before they are marked
stable.
Add media.copiesOf to the route's reader and imageCopies to the route above, and a
visitor downloads each image at about the size it is drawn, not at its upload size:
// src/app/(frontend)/[...slug]/page.tsx
import { createPublicBlocksPage } from "@nextlyhq/blocks-react/next";
import { pageBuilderImageCopies } from "@nextlyhq/plugin-page-builder";
import { getNextly } from "nextly";
import type { NextlyContentReader } from "nextly/runtime";
import nextlyConfig from "../../../../nextly.config";
type NextlyInstance = Awaited<ReturnType<typeof getNextly>>;
const instance = () => getNextly({ config: nextlyConfig });
// The reader above, whose media now also answers for an image's copies.
const reader: NextlyContentReader & {
media: Pick<NextlyInstance["media"], "findByID" | "copiesOf">;
} = {
find: async args => (await instance()).find(args),
findByID: async args => (await instance()).findByID(args),
media: {
findByID: async args => (await instance()).media.findByID(args),
copiesOf: async args => (await instance()).media.copiesOf(args),
},
};
const route = createPublicBlocksPage({
collections: ["pages"],
field: "content",
nextly: reader,
// Your route's other options stay as they are, its `styleContext` among them.
imageCopies: pageBuilderImageCopies(reader),
});The copies are the resized versions your site's media already keeps, from 96 to 1920 pixels wide and never wider than the upload. With the option set:
- An Image block from the media library offers its copies with
srcsetandsizes. How wide it is drawn on each device comes from your breakpoints: the whole width at the top of the page, shared out across a row of Columns, and narrowed by a width or maximum width the block sets for itself on every device. No copy more than twice the widest of those is sent. - The page's first block loads first. The images in the first top-level block load at once and with high priority. Every other image keeps its lazy loading.
- The first section's background image is sized and found early. Where the first
top-level block sets a background image once, for every device and in its resting
state, at a size the box sets (
cover,containor a length), each device draws a copy about twice its width. The page's<head>preloads each copy for the viewports it is drawn at, so the browser starts on it before the stylesheet arrives. - Each image's copies are looked up once, then kept until the image or its copies change.
The original is drawn as it always was when:
- the route has no
imageCopies; - the image is given by its address rather than picked from the media library, so its width and height are not known; or your storage keeps no resized copies;
- the upload is narrower than the smallest copy, or the lookup fails;
- for the background, its address is not the media route's (
/api/media/<id>/raw), so no media item is named by it; it is drawn at the image's own size (no size, orauto), which a narrower copy would shrink; or it changes by device or on hover, it is layered with a gradient, or the block has custom CSS.
One process, several sites
A page reads everything through the nextly it is given: its entry, the lists and Singles it
shows, and the site settings, the site's name, address, logo and the time zone its dates and day
filters use. A process serving several sites, each through an instance of its own, gives each
route its own nextly, and each page shows its own site. Only a route given no nextly reads the
process's registered instance.
Bind each of those routes to its site's blocks too, with blocks: blocksOf(builder) from
@nextlyhq/plugin-page-builder, where builder is that site's pageBuilder(). A route given
no blocks reads the blocks of the process's registered instance. The same goes for
loadSiteStyle, which takes the same blocks. One limit remains: a plugin that adds blocks in
code from its init (blockRegistry(ctx).register) reaches the page builder whose site started
last, because a process keeps one set of plugin services. Blocks a plugin declares under
contributes.declarations reach each site's own page builder. And while two sites run at once,
a save is judged by the field rules of the site that started last, for the same reason: a
process keeps one set of field types. In a production build each route holds its own copy of
the plugin, which never starts, so blocksOf(builder) and namedQueriesOf(builder) read the
started site's through the instance there; on a process running two sites at once, that is the
site that started last.
Give each of those routes its own cacheScope too, such as the site's id. Every public read a
route makes, its site settings among them, is cached under it, and two routes over different
instances with the same scope, or none, share their cached reads.
A reader of your own forwards publicSiteSettings from the instance, as the example above does.
A reader without it still shows the settings of the process's registered instance, as it did
before, so a single-site app keeps working. On a process serving several sites those are
another site's settings, so the route warns once per reader, in every environment, naming the
line to add.
Hold the body in a boundary
Under Cache Components, wrap your root layout's <body> in a <Suspense>, as the
routing guide shows. On a fresh deploy the database is
seeded after next build, which expires every page the build kept, and the first visit
draws each page again. Without a boundary above the body, a read there that isn't cached
answers 500. React never sends a boundary that holds the body hidden, so a visitor without
JavaScript still gets the whole page.
Pages only some visitors may read
createPublicBlocksPage reads trusted and pre-renders, so it reads the database during
next build, and every visitor gets the same page. Where your collection's access rules
decide who may read a page, call createBlocksPage instead: it reads as each visitor
would, renders every visit, needs no database at build, and returns no
generateStaticParams. Which one you call is the security posture — there is no option
to flip.
Either one previews drafts with draft: previewDraftGate(). On createPublicBlocksPage
the gate is asked only on a preview link's request, which Next.js renders on demand and
never caches, so the cached page is never a draft.
Draw the canvas in your site's layout
The editor's canvas can draw the page inside your own site's layout, so your global stylesheet, fonts, header and footer are around it, as they are around the published page. Add one route, inside the same layouts your pages are published in, that renders the canvas's empty page:
// src/app/(frontend)/page-builder-canvas/page.tsx
export { PageBuilderCanvas as default } from "@nextlyhq/plugin-page-builder/canvas";Then name the route's path in the plugin's options:
pageBuilder({ canvasPath: "/page-builder-canvas" });The editor loads that page into the canvas and draws the page being edited in it. Your layout stays visible around the page, faded and inert: its links and forms do nothing in the editor. The route renders no content of its own and reads nothing, and it tells search engines not to index it.
The path must be on the same site as the admin, since the editor draws into the page it
loads. If your pages sit under their language, write {locale} where the code goes, as in
canvasPath: "/{locale}/page-builder-canvas". The editor then loads the route for the
language being edited, and leaves the segment out for your default language. Without canvasPath, the canvas draws the page on a blank page of its own. It does
the same when the route is set but not found or does not load, and then a note above the
canvas says so, with a link to this section. On the blank page the page has its block
styles and the site's shared styles, but not your app's own CSS files, such as a
globals.css that styles h2 or body.
Pointing at your layout around the page shows that it is part of your site's layout, which is edited in your site's code rather than in the editor.
The canvas wraps the page in an element of its own, which the editor needs. A layout rule
that selects your page as a direct child, such as main > .nx-pb-page, doesn't match in
the canvas.
On the blank page, a block that blends over a translucent site background (a block with
mix-blend-mode over a background colour that is partly transparent) can look different in
the editor than when published. Over an opaque background it looks the same.
Breakpoints
Breakpoints are desktop-first. The base breakpoint applies at every width. Each other
breakpoint has a maxWidth, and the values a block is given for it apply at that width
and below, as an @media (max-width: …) rule.
A site that states no breakpoints, in its config, its route or the editor, has the built-in
ones: Tablet at 1024px and Mobile at 640px. The canvas and the published pages use the
same set, so a Menu left at its default shows "☰" on phones from the start. They are never
stored: the screen size editor lists them, and changing one saves your own set, which then
replaces them whole. A site always keeps at least one screen size, since removing them all
would bring the built-in ones back. A host stating its own set in code states it in
pageBuilder({ siteStyle }) as well as in its route's styleContext, so the editor draws
the same sizes the route publishes.
In the editor, the device buttons choose which breakpoint you are styling. The base
breakpoint is named Desktop. The width the canvas lays the page out at is shown beside
the buttons: Desktop at 1280px (or one pixel past your widest breakpoint, if that is
wider), and every other breakpoint at its own maxWidth, so "1024px" for a Tablet at
1024px. Each button's tooltip names its device with that width and the widths it styles. The Style
tab edits the values for that breakpoint. The screen size editor beside the buttons adds,
changes and removes the site's breakpoints.
The device is your choice alone. Opening or closing a panel, or a narrower window, changes only how far the canvas is zoomed to fit; the zoom menu reads "Fit · 72%" while it fits. Choose a fixed zoom from the menu, press Ctrl+0 (⌘+0 on a Mac) for actual size, or Shift+1 to fit again. Choosing another device goes back to fitting. The editor remembers the device and the zoom you left, for you rather than for the browser. If you remove the breakpoint you are styling, the editor moves to the next wider breakpoint that remains, or to Desktop when none is wider. A breakpoint removed while you were away is replaced by Desktop when you come back. If someone else removes a breakpoint while you still have the editor open, a save that adds styles or hiding at it is refused with "That screen size was removed from the site. Reload to keep editing.", since the published page would never show them. Styles a page already held there still save.
Limits
- Styles only. What changes per breakpoint is what the Style tab sets. A block's content and settings are the same at every width.
- A width, not a device. The device buttons choose a breakpoint and lay the canvas out
at its width; they do not show the page as a particular phone or tablet would. The canvas
is a frame of its own at that width, so sizes in
vworvh,@mediarules you write yourself and code that reads the window's width answer for the device, as they do on the published page. - Your site's global stylesheet reaches the canvas through its canvas route. With
the canvas route mounted, the canvas is drawn in
your site's layout and takes your app's own CSS. Without it, rules from your app's CSS
files, such as a
globals.cssthat stylesh2orbody, do not reach the canvas, and boxes size asborder-box, which most site resets set. - Saved breakpoints reach a page only when its route reads them. Breakpoints you save
in the editor are stored in the plugin's
site-stylesingle. The route above compiles against the breakpoints it declares instyleContextand never reads that single, so a breakpoint added in the editor styles the canvas but not the published page. To serve what the editor saved, passsiteStylestocreateBlocksPage, withloadSiteStyleandSITE_STYLE_SLUGfrom@nextlyhq/plugin-page-builder, and give the readerfindSingle, addingNextlySingleReaderfromnextly/runtimeto its type:
// src/app/(frontend)/[...slug]/page.tsx, serving the breakpoints the editor saved
import { createBlocksPage } from "@nextlyhq/blocks-react/next";
import { loadSiteStyle, SITE_STYLE_SLUG } from "@nextlyhq/plugin-page-builder";
import { getNextly } from "nextly";
import type {
NextlyContentReader,
NextlySingleReader,
PublicSiteSettingsSource,
} from "nextly/runtime";
import nextlyConfig from "../../../../nextly.config";
type NextlyInstance = Awaited<ReturnType<typeof getNextly>>;
const instance = () => getNextly({ config: nextlyConfig });
const reader: NextlyContentReader &
NextlySingleReader &
PublicSiteSettingsSource & {
media: Pick<NextlyInstance["media"], "findByID">;
} = {
find: async args => (await instance()).find(args),
findByID: async args => (await instance()).findByID(args),
// The site style is a single, read through this.
findSingle: async args => (await instance()).findSingle(args),
publicSiteSettings: async () => (await instance()).publicSiteSettings(),
media: {
findByID: async args => (await instance()).media.findByID(args),
},
};
const { ContentPage, generateMetadata } = createBlocksPage({
collections: ["pages"],
field: "content",
nextly: reader,
siteStyles: {
read: () => loadSiteStyle({ nextly: reader }),
// Named so that saving the site style refreshes cached pages.
singles: [SITE_STYLE_SLUG],
},
// Used until breakpoints are saved in the editor: a new site has none
// stored. Optional: with none stated anywhere, the built-in Tablet and
// Mobile sizes apply.
styleContext: {
breakpoints: {
viewport: [
{ id: "base", label: "Base" },
{ id: "tablet", label: "Tablet", maxWidth: 1024 },
{ id: "mobile", label: "Mobile", maxWidth: 640 },
],
container: [],
},
},
});
export { generateMetadata };
export default ContentPage;What reaches the browser
A published page is rendered on the server by @nextlyhq/blocks-react. What a visitor's
browser receives is the page's HTML and CSS, plus whatever JavaScript the page itself
loads:
- The editor stays in the admin.
@nextlyhq/builderand the plugin's editor code run only on the admin's builder screen. Your page route imports@nextlyhq/blocks-react, a server renderer with no client components, so none of the editor is sent to visitors. - The core blocks add no JavaScript of their own. None of the 20 core blocks is a
client component. The accordion is a native
<details>, and the form block is a plain HTML form that posts where you point it. - The page still loads Next.js. Every App Router page carries the Next.js and React runtime, and whatever your layout adds. "No JavaScript of their own" is about the blocks, not the page.
- The embed block can run scripts. It is an iframe sandboxed with
allow-scripts, so what you embed runs in the visitor's browser, inside the frame. A YouTube, Vimeo, Spotify or Google Maps player also keeps its own origin, which those players need, and by default it loads only when a visitor presses play on the poster: until then the frame holds a small poster document with no script, written into the frame'ssrcdoc. If your site sends a Content Security Policy, the poster's inline styles needstyle-src 'unsafe-inline', and the players' hosts need to be allowed inframe-src. - Your own blocks decide for themselves. A block whose component is, or renders, a client component sends that component's JavaScript with every page that uses it.
- Styles arrive as CSS. They are compiled on the server into
<style>elements in the page: the site's shared sheet and the page's own rules. - Editor markers stay out. The
data-nx-*attributes the canvas uses to select blocks are written only when the editor asks for them. - Hidden is not always absent. A block hidden at a breakpoint is in the HTML and hidden with CSS. A block that carries display conditions is left out of the HTML, styles included.
The editor's canvas draws your page with the same React renderer that serves it,
PageRenderer from @nextlyhq/blocks-react. It is not pixel-identical to the published
page: the editor draws its outlines and markers over the canvas, and your app's own global
stylesheet reaches it only through the canvas route.
The page is drawn in a frame of its own at the device's width, so viewport units and your
own @media rules answer as they do when published, and neither the admin's styles nor the
page's reach the other.
Use it as a field instead
You do not have to accept the pages collection. The builder is also a field, usable in
any collection or single next to ordinary fields:
import { blocks } from "@nextlyhq/plugin-page-builder";
import { defineSingle, text } from "nextly/config";
export const Homepage = defineSingle({
slug: "homepage",
fields: [text({ name: "title" }), blocks({ name: "content" })],
});A page's address
A page's address is its slug, and it may sit beneath another page's: type
docs/getting-started/install in the slug and the page is served at
/docs/getting-started/install. Each part is normalised as a one-part address
is (Getting Started becomes getting-started), and one leading or trailing /
is dropped. An address with an empty part (docs//install), a . or .. part, a
part with no letters or numbers left, a reserved path (admin, api/...,
_next/..., one part or several) or more than 255 characters is refused when the page is saved, with
the reason under the slug, rather than rewritten into an address nobody chose. A
copy of a nested page stays beside it (docs/copy-of-install).
The Pages collection opts into this with db: { slugPaths: true }, which any
collection may set. It is a rule about the stored value only: no schema change
or migration follows, no stored address is rewritten, and a collection
without it keeps stripping / from its slugs. Two pages at one address are kept
apart by the slug's uniqueness, as before.
One address, one page
A published page holds its address, and a page whose Collection list is split into
pages also holds that list's later pages (/news/page/2, /news/page/3, …) as one
space, however many pages the list has today. Saving a page that would share an
address with another document is refused, naming the other document: publishing a
page at /news/page/2 while the page at /news splits its list into pages, or
splitting the list at /news into pages while a page is published at
/news/page/2. The other document is named by its title where you may read it, and
by its id where you may not. The address is held from the save that publishes the
page, in the same transaction, so two saves at once can't both take it, whichever
way the pages were saved (the editor, the API, a batch, a release or a scheduled
publish). Unpublishing or deleting the page frees its address; turning off Split
into pages frees the later pages and keeps the page's own address. A site upgrading
to this claims its published pages' addresses in the background after start-up,
oldest first; a page that clashes with an older one waits for it and appears in the
waiting report.
Serving a collection's entries
A collection defined in code can serve each of its entries at its own address, drawn with the collection's template. Declare where in the plugin's options:
pageBuilder({ templates: { addresses: { posts: "/blog" } } });Once the collection's template is published, each published post is served at
/blog/<its slug>. Write the address as a visitor requests it: starting with
/, ending without one, with no empty or . segment, and not / itself or under
a path the runtime keeps (/admin, /api, …). Two collections may not share an
address, and the collection needs a slug text field. Anything else stops the
site from starting, naming what is wrong.
An entry's address is held like a page's, from the save that publishes it: saving an entry at an address another document holds is refused, naming it, and unpublishing, deleting or renaming the entry frees it. When a template is first published over entries whose addresses a page already holds, those entries wait and are served as soon as the page frees the address.
Pages and entries are served by one route, which answers every path from the addresses the site holds. Visitors are served from the cache: each published path is built ahead of time, and publishing or unpublishing a page, its header or footer, a component it places or the site style refreshes the pages that use it. So does saving, closing or deleting a form a page places, through a provider that names its tags (Forms).
import { createPublicContentPage } from "@nextlyhq/blocks-react/next";
import { pageBuilderContent } from "@nextlyhq/plugin-page-builder";
import { previewDraftGate } from "nextly/runtime";
const route = createPublicContentPage({
...pageBuilderContent(),
pages: {
collections: ["pages"],
field: "content",
draft: previewDraftGate(),
},
});
export async function generateStaticParams() {
const params = await route.generateStaticParams();
// Until something is published, build one path that answers not found:
// Next.js refuses an empty list when Cache Components is on.
return params.length > 0 ? params : [{ slug: ["not-found"] }];
}
export const { generateMetadata } = route;
export default route.ContentPage;A preview link opens on the page's own address and shows the draft of the one entry it
names. Opening the link turns on Next.js's draft mode, and only a request in draft mode
asks previewDraftGate(). Next.js renders those requests on demand and never caches
them, so every other visitor keeps getting the published page from the cache. The route
reads the database during next build, so run nextly plugins install before the first
build: against a database without the plugin's tables, the build stops and names the
command.
A page is served as createBlocksPage serves it. An entry is drawn with its
collection's published template, reading the entry as a visitor would, and takes
its title, description and image from the template's SEO settings. A path nobody
holds is not found, and so is an entry with neither a published template nor a
published own design (below).
A site set up from the earlier example, createContentPage with
draft: previewDraftGate(), keeps working unchanged, but renders every visit. To serve
its visitors from the cache, call createPublicContentPage instead, with the same
options, and export the generateStaticParams shown above. Previews keep working at the
same addresses.
To do something for each address the route does not find, such as logging it, pass
your own notFound beside pages: a function that answers the miss as Next.js's
notFound() does. The route calls it in place of notFound(), from the page and
from generateMetadata alike, for a page and an entry; a handler that returns is
followed by notFound(). createBlocksPage and createSinglePage take the same
option. It is experimental: its name and shape may change before 1.0. The public forms
(createPublicContentPage, createPublicBlocksPage, createPublicSinglePage) call it
only with Cache Components on: without them a public page's answer is rendered once and
kept, so a miss there is answered by notFound() and the handler is not called.
An entry with its own design (An entry's own design)
is drawn with that design instead, and takes its SEO settings from it, once the design
is published. Until then, and after it is removed, the entry keeps its collection's
template. A draft own design is never drawn by this route, in preview mode too:
preview it in the editor. Publishing, unpublishing or
removing an own design refreshes the entry's cached page, as a change to the template
does. The design is read with the template in one query, through
pageBuilderContent()'s templates.readFor; a provider written by hand without it
draws every entry with its collection's template.
An entry's list split into pages
Where the design drawing an entry (its published own design, else its collection's
published template) splits a Collection list into pages, the entry holds that list's
later pages beside its address, as a page does: /blog/hello/page/2,
/blog/hello/page/3 and on, as one claim, and the route serves each by drawing the
entry with that page of the list. /blog/hello/page/1 redirects to /blog/hello,
and a page past the list's last is not found. Saving an entry where a document is
published among those later pages is refused, naming it. Publishing a paged template,
turning on Split into pages in a published one, or publishing a paged own design
leaves an entry whose later pages a page already holds at its own address, waiting:
its list shows one page, linking to no later page, until the page frees the address,
then pages without the entry being saved. An entry left waiting for its own address,
because another document holds it, waits for its later pages as well, and is given both
together once that document frees the address. Turning Split into pages off, unpublishing the paged design, or
removing it frees the later pages and keeps the entry's address. Later pages are not
pre-rendered by createPublicContentPage; each renders on its first request.
An entry keeps its address while its own design is published, even when its collection's template is unpublished or deleted: those entries stay served, and every other entry of the collection gives its address up. Unpublishing or removing the own design then gives the entry's address up too, unless the template is published. Publishing an own design claims the entry's address without the entry being saved; where another document holds it, the entry waits for it. The address itself still comes from the collection: an address declared in code, or the one stored on its template. A collection made in the Schema Builder whose template is deleted has no address left, so none of its entries is served, own design or not.
Collections made in the Schema Builder
A collection made in the Schema Builder has no code to declare its address in, so
its template stores it. Open Collection templates in the Page Builder's panel, open the
collection's template and set its Address; once the template is published its
entries are served there, with no restart. The same rules apply as to an address
declared in code, and an address declared in code wins over a stored one. When you
promote such a collection into code with nextly db:sync --promote, the line that
declares its address is printed beside its code; the stored address keeps serving
until the declaration takes over at the next start.
Setting or changing an address needs the Manage template routing permission
(manage-template-routing), apart from updating templates, since it moves every
entry's live address. Anyone else sees the address read-only, and an address they
send through the API is left out of their save. Changing a template's address frees
the old address of every entry it serves (all of them while it is published, those
with a published own design while it is not) and serves each at the new one; an
entry whose new address another document holds waits for it. API clients use the
set-template-address template action, which has a dry run.
Reading content into a page
The Collection list block (stored as core/collection-loop) queries one of your
collections and repeats its child blocks once per entry — a post list, a team grid, a
product row — without anyone writing a query. The developer decides which collections are
available to it; the editor decides which entries it shows and what each one looks like.
In the editor, the list's Content tab edits its query, under Entries:
- Show entries from: a collection, or a to-many relation of the page's entry (on a collection's entry) or of each item of the list around it, such as a post's categories.
- Filters: rows an entry must all meet, each read as one sentence, for example Title contains "build" or Published is on or after 1 Sept 2026. Only fields visitors can see are offered, and none holding several values.
- Sort: one row per key, each with its direction in words (Newest first, A–Z, Highest first). Entries with the same values keep a fixed order, and entries with no value come last.
- Entries shown: How many (1 to 100), Skip, and Split into pages. Under How many the selected list says how many entries match and how many show, for example "4 entries match, so 3 show.", counted as you read them on the canvas. Under Split into pages, while it is on, it says how many pages that makes, for example "24 entries match, so 3 pages of 10." See Splitting a list into pages.
- When nothing matches: Preview the empty message, to design the list's empty state, which visitors see when no entry matches.
The list's HTML tag (Advanced, HTML) renders it as a generic box, a section or an article.
A prop bound to the page's own entry or to a Single shows, on the canvas, the value you could see in the admin, your drafts included, read with your own access; one you may not read shows its fallback. The published page reads the same sources as a visitor. The site settings and the fields a binding is checked against are the public's on both.
The canvas draws each list with the entries you could see in the admin: your drafts
included, and only the entries and fields your own access lets you read. The published
page reads the same list as a visitor: published entries and public fields only, so a
draft you see on the canvas never appears there. A filter or sort the published page
would refuse is refused on the canvas too. When a stored sort falls
back to id order or the read fails, the canvas says so in a note only the author sees; a
fallen-back sort's note has a Choose a field button that takes the author to the sort.
Near midnight the canvas may differ from the published page for a day filter: the canvas
compares days in UTC, the published page in the site's time zone. The same query can be
set through the API with set-list-query.
Splitting a list into pages
Turn on Split into pages and the list shows How many entries on each page, each
page at its own address: the list on /news shows its first page there, the second at
/news/page/2, the third at /news/page/3, and so on. Under its entries the list draws
links to the previous and next pages and the page numbers, as ordinary links a visitor can
share and a search engine can follow. The links are parts of the list (Pages, Page link,
Current page and Page gap), so the Style tab styles them as it styles the list; by default
they are outlined boxes, with the current page filled in the site's primary colour.
- Skip is applied once, before paging: with 25 entries, 10 skipped and 10 on a page, page 1 shows entries 11 to 20 and page 2 entries 21 to 25, the last.
/news/page/1redirects permanently to/news, so the first page has one address. A number past the last page, or written any other way (/page/0,/page/02,/page/1.5), answers not found.- When no entry matches,
/newsshows the list's empty state and every later page is not found. - Each page has its own canonical URL. On a public route, every page that exists at build
is pre-rendered, within the route's
staticParamsLimit; a page that comes to exist later, as the list grows, renders on its first visit and is cached from then on. - An entry stored at such an address (a page whose slug is
news/page/2) is served as itself, ahead of the list's page.
One list on a page can be split into pages, so the page's address names one list's page. The save is refused, naming the reason, for a second list split into pages on the same page, a list split into pages inside another list (it repeats once per outer entry, with no address of its own), a list of related entries (they have no count of pages), and a list in a component or a header & footer region (each shows on many pages). A list on a Single's page shows its first page only, since a Single's route serves no later pages.
The loop reads through the route's public reader, which every blocks route binds to each
render. With no data option the loop reads through it directly, so a published page lists
published entries with no wiring. To name the collections a loop may read, pass data, a
function from that reader to a provider:
import { createDefaultDataProvider } from "@nextlyhq/blocks-react";
import { createBlocksPage } from "@nextlyhq/blocks-react/next";
const { ContentPage, generateMetadata } = createBlocksPage({
collections: ["pages"],
field: "content",
// ...and the rest of the options above...
// The collections an editor's loop may list. Anything else reads nothing.
data: reader => createDefaultDataProvider(reader, { collections: ["posts"] }),
});data takes a function, never a provider object: a provider holding a reader of its own would
decide by itself who sees what, so the route refuses one when it is built. Each list read is
cached like the page and tagged with its collection, so publishing a post refreshes the pages
that list it. A change to a collection's access rule is not a write, so a page cached before it
shows the old answer until it revalidates.
A list always sends a sort, so a list with none comes back in id order. If the reader refuses a loop's stored sort (a field since removed, or one the public may not read), the loop lists in id order instead of going empty.
A provider you wrote yourself, for PageRenderer outside a route, now receives sort as one
key or an array of keys, and an empty array for a loop with no sort. Read it as "no sort
given": [sort ?? []].flat() gives the keys either way.
The reader is createPublicReader (from nextly/runtime, @experimental), which you can also
call yourself over a Nextly instance. It takes a list's query as data and fixes everything that decides who sees what:
- published entries only, judged by each collection's read rule as an anonymous visitor;
- fields the public may not read never come back, and filtering or sorting on one is refused;
- a sort key that names no field is refused, not dropped, and ties come back in id order;
limit(1 to 100),offsetandpageare checked, and the read answers in the route's language.
A query that tries to widen the read (status, overrideAccess, user, a raw where, and
so on) is refused by name rather than ignored. This is a contract your provider relies on,
not a sandbox: code holding the Direct API can still read whatever it is trusted to.
Filter rows are typed { field, op, value }, with op one of equals, not_equals, gt,
gte, lt, lte, contains, in, not_in and exists. contains ignores case on every
database, for letters outside ASCII too (the Turkish "İ" matches a plain "i").
Singles, site settings and field shapes
The public reader also reads one Single, as an anonymous visitor would:
import { createPublicReader, type PublicReaderSource } from "nextly/runtime";
// A Nextly instance, such as the one `getNextly()` answers.
declare const nextly: PublicReaderSource;
const publicReader = createPublicReader(nextly);
const banner = await publicReader.findSingle({
slug: "banner",
select: ["headline"],
});It answers the published document with the fields the public may read, or null when there is
nothing a visitor may see: no document yet, one never published, or a Single the visitor may not
read. It never creates the Single's document. select keeps the id and the fields named; the
read takes no other option, and refuses status, draft, depth, populate and the rest by
name, as a list's read does.
Three more reads sit beside it in nextly/runtime, each @experimental:
readPublicSiteSettings()answers the site'sapplicationName,siteUrl,logoUrlandtimezonefrom the General Settings, eachnulluntil it is set. Nothing else in the settings comes back: not the administrator's email, not the preview links' revocation counter, and not a setting added later. Saving the settings expires the tagnextlySiteSettingsTags()names, so tag a cached read with it and a page shows a new site name or time zone on its next request. Given an instance,readPublicSiteSettings(nextly)reads that instance's settings instead, through the same allowlist; an instance answers the same fromnextly.publicSiteSettings().bindingFieldShapes({ collection })orbindingFieldShapes({ single })answers the fields a visitor may read, each with itstype, and where they applyhasMany,relationTo, the select or radiooptions, anddateOnlyormonthOnlyfor a date picked as a day or a month. A field the visitor's field rules hide is left out, and so is one whose rule needs an entry to decide. A source the visitor may not read, or one that does not exist, has no shapes (undefined).declaredFieldShapes({ collection })ordeclaredFieldShapes({ single })answers the same shapes for every field the source declares, whoever may read it: what a save checks a binding against (see Bindings checked when a document is saved). A source that does not exist has no shapes (undefined).
The shapes, and the settings when no instance is given, read the process's running instance,
as requireNextly does.
Field bindings inside a loop are resolved when the page renders: each repeated item shows its own entry's fields. A binding with no value shows its fallback, or the text its block was given in the editor. See Block document format.
A quote
The Quote block (stored as core/quote) holds the quoted words, Who said it
and the Source it comes from. Its Source link is the same link every block
uses: an address, or a page or entry of your site, opened in a new tab if you like,
with its relationship in Advanced. On the page, the link becomes the quotation's
cite and links the source's title. The dash before the person's name is drawn by
the page's styles, so it is never part of the words a reader copies.
A Quote has three block styles: Line, its own, a line beside the words in your site's accent colour; Plain, with no line; and Large, bigger centred words. They look the same in the editor and on the live page. A Quote saved before its source was a link keeps that address as its Source link.
A table of contents
The Table of contents block (stored as core/table-of-contents) lists the page's
own headings, in page order, each linking to its heading. There is nothing to fill in:
add, rename or move a heading and the list follows, on the canvas at once. It lists
Heading blocks, the headings inside Rich text blocks and, on a collection's template, the
headings of each entry's own body, by the entry's words. It leaves out the headings in
the site's header and footer, inside a Collection list or an Accordion (a link into a
closed question does not open it in every browser), headings hidden on every device, and
any heading you leave out (below).
- Headings: H2 only, H2 and H3 (the default), or H2 to H4. An H1 is the page's title and is never listed. Each heading sits inside the heading above it, in a nested list, so a screen reader announces the structure as well as the words.
- List as: Numbers (the default, nested as 1, 2, 2.1) or Bullets. The numbers are drawn by the stylesheet, so a screen reader, which already says each entry's place, does not read them twice.
- Title: the label above the list (On this page by default), which also names the block's navigation landmark.
- Can be folded: on by default, so the list starts open under its title and a reader can close it, with no script.
- Highlight the section being read: on by default. In browsers with CSS scroll-linked targets (Chrome and Edge today) the entry for the section in view is set in a heavier weight as the reader scrolls; elsewhere the list works the same, without the highlight. No script is added for it.
A Table of contents saved before it listed the page's headings is upgraded when the page is read: the passage it was bound to is no longer read, its other settings are kept, and it lists the page's headings with bullets, as it drew none before. A binding on its old Content goes with it, as does a component setting that exposed it.
Every heading on a page carries an id, so a link can reach its section: each Heading
block, and each heading inside a Rich text block, in the header and footer too. The id is
the heading's own Anchor (ID) when you set one in Advanced; otherwise it is made from
its words: lower-cased, punctuation dropped, spaces as hyphens, letters in any script kept
(Getting started is #getting-started, Über uns is #über-uns). Ids are unique on
the whole page: a repeated heading is numbered in page order (#notes, #notes-2,
#notes-3), whichever blocks it is in, and a made id never takes one you gave any block.
A heading inside a Collection list is drawn once per entry, so each copy of a made id
adds its entry's place (#title--0, #title--1).
Any heading can be left out of a table of contents: select it, and in Advanced › Visibility turn on Leave out of table of contents. It keeps its id, so a link written by hand still reaches it.
A visitor sees nothing when there are no headings to list, so an entry without any shows no empty box. On the canvas the block keeps its frame and says "Add H2 headings to this page and they'll be listed here."
Related
- Using the editor — the rail, the panels and the keyboard shortcuts
- Block document format — how a page is stored
- Blocks from plugins — add blocks, and their own inspectors, from a plugin
- Plugins — the SDK this plugin is built on
- Preview — see a page before it is published
- Routing and SEO — how paths resolve