# 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

* **21 blocks out of the box.** Layout (section, box, columns, column, card, accordion,
  accordion item, spacer, divider), content (heading, paragraph, rich text, list, quote,
  image, gallery, icon, button, embed, form), and one that reads from your content
  ([Collection list](#reading-content-into-a-page)).
* **Icons.** The Icon block draws one icon from the built-in [Lucide](https://lucide.dev)
  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.
* **Accordion titles and icons.** An accordion's **Titles as** (Content tab) draws each
  section's title as text or as a heading from level 2 to 6, and its **Icon** and
  **Position** (Style tab) choose a chevron, a plus, no icon or the browser's own triangle,
  before or after the title. Some screen readers announce a section title as the button's
  text rather than as a heading; the section still opens and closes as normal.
* **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](#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](#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                              |

## Install

```bash
pnpm add @nextlyhq/plugin-page-builder @nextlyhq/blocks-react \
  @nextlyhq/builder @nextlyhq/plugin-sdk react-hook-form
```

Add the plugin to your config. It contributes a `pages` collection whose edit screen is
the builder:

```ts
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:

```bash
npx nextly plugins install @nextlyhq/plugin-page-builder
```

The 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, and that file also loads the editor's styles, 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](https://nextlyhq.com/docs/plugins/admin-ui.md).

An admin page that still imports `@nextlyhq/plugin-page-builder/styles/editor.css` by hand
keeps working: it loads the same stylesheet, once. You can remove the import.

## Render the pages

A plugin cannot add routes to your Next.js app, so you declare one catch-all route and
let `createBlocksPage` fill it. It resolves the incoming path against your collections,
404s on a miss, and renders the stored document.

```tsx
// src/app/(frontend)/[...slug]/page.tsx
import { createBlockResolver } from "@nextlyhq/blocks-react";
import { coreBlocks } from "@nextlyhq/blocks-react/blocks";
import { createBlocksPage } 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 { ContentPage, generateMetadata } = createBlocksPage({
  collections: ["pages"],
  field: "content",
  nextly: reader,
  blocks: createBlockResolver(coreBlocks),
  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;
```

> [!WARNING]
> Without a breakpoint set the renderer emits class names with no CSS behind
> them, and pages come out structurally correct and visually bare. Declare at
> least a `base` breakpoint.

### 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.

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.

### Public sites read differently

`createBlocksPage` reads **access-enforced** content, so it needs no database during
`next build`. A wholly public site calls `createPublicBlocksPage` instead: it reads
trusted, pre-renders, and returns a `generateStaticParams` to export alongside the other
two. Which one you call *is* the security posture — there is no option to flip.

## 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:

```tsx
// 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:

```ts
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.

In the editor, the device buttons choose which breakpoint you are styling. The base
breakpoint is named **Desktop**. The chosen device shows the width the canvas lays the
page out at: Desktop at 1280px (or one pixel past your widest breakpoint, if that is
wider), and every other breakpoint at its own `maxWidth`, so "Tablet · 1024px". The Style
tab edits the values for that breakpoint. The breakpoint manager 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 <kbd>Ctrl</kbd>+<kbd>0</kbd> (<kbd>⌘</kbd>+<kbd>0</kbd>
on a Mac) for actual size, or <kbd>Shift</kbd>+<kbd>1</kbd> 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 breakpoint 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 `vw` or `vh`, `@media` rules 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](#draw-the-canvas-in-your-sites-layout) 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.css` that styles `h2` or `body`, do not reach the canvas, and
  boxes size as `border-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-style` single. The route above compiles
  against the breakpoints it declares in `styleContext` and 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, pass `siteStyles` to `createBlocksPage`, with `loadSiteStyle` and
  `SITE_STYLE_SLUG` from `@nextlyhq/plugin-page-builder`, and give the reader
  `findSingle`, adding `NextlySingleReader` from `nextly/runtime` to its type:

```tsx
// src/app/(frontend)/[...slug]/page.tsx, serving the breakpoints the editor saved
import { createBlockResolver } from "@nextlyhq/blocks-react";
import { coreBlocks } from "@nextlyhq/blocks-react/blocks";
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,
  blocks: createBlockResolver(coreBlocks),
  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, and with no breakpoint set the page gets no stylesheet.
  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/builder` and 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.
* **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](#draw-the-canvas-in-your-sites-layout).
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:

```ts
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:

```ts
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:

```tsx title="app/(frontend)/[...slug]/page.tsx"
import { createContentPage } from "@nextlyhq/blocks-react/next";
import { pageBuilderContent } from "@nextlyhq/plugin-page-builder";
import { previewDraftGate } from "nextly/runtime";

const { ContentPage, generateMetadata } = createContentPage({
  ...pageBuilderContent(),
  pages: {
    collections: ["pages"],
    field: "content",
    draft: previewDraftGate(),
  },
});

export { generateMetadata };
export default ContentPage;
```

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 whose collection has no published template.
`createPublicContentPage` is the cached, pre-rendered form.

#### 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 **Templates** in the page builder's menu, 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 published template's
address frees every entry's old address and serves it 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:

* **Source**: 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.
* **How many**: Number of items (1 to 100), Skip the first, and Split into pages. Under
  Number of items 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](#splitting-a-list-into-pages).
* **When nothing matches**: Canvas shows Entries or When empty, to design the list's empty
  state, which visitors see when no entry matches.

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`](https://nextlyhq.com/docs/page-builder/compose-through-the-api.md).

### Splitting a list into pages

Turn on **Split into pages** and the list shows Number of items 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 the first 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/1` redirects 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, `/news` shows 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 Layout 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:

```tsx
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), `offset` and `page` are 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 same reader also reads one Single, as an anonymous visitor would:

```ts
const banner = await reader.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's `applicationName`, `siteUrl`, `logoUrl` and
  `timezone` from the General Settings, each `null` until 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 tag `nextlySiteSettingsTags()` 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 from `nextly.publicSiteSettings()`.
* `bindingFieldShapes({ collection })` or `bindingFieldShapes({ single })` answers the fields a
  visitor may read, each with its `type`, and where they apply `hasMany`, `relationTo`, the
  select or radio `options`, and `dateOnly` or `monthOnly` for 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 })` or `declaredFieldShapes({ 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](https://nextlyhq.com/docs/api-reference/block-document-format.md#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.

> [!WARNING]
> Field bindings inside a loop are stored but not resolved yet. Each repeated
> item shows the text its blocks were given in the editor, not the entry's own
> fields. See [Block document
> format](https://nextlyhq.com/docs/api-reference/block-document-format.md).

## Related

* [Using the editor](https://nextlyhq.com/docs/page-builder/editor.md) — the rail, the panels and the keyboard shortcuts
* [Block document format](https://nextlyhq.com/docs/api-reference/block-document-format.md) — how a page is stored
* [Blocks from plugins](https://nextlyhq.com/docs/page-builder/contributed-blocks.md) — add blocks, and their own inspectors, from a plugin
* [Plugins](https://nextlyhq.com/docs/plugins.md) — the SDK this plugin is built on
* [Preview](https://nextlyhq.com/docs/preview.md) — see a page before it is published
* [Routing and SEO](https://nextlyhq.com/docs/guides/routing-and-seo.md) — how paths resolve
