# Defining a page type

A page type is a page component with zones: the places where editors add sections. This page walks through the Lorem Co. starter's Home and Page types, and what a page type learns about its place in the site.

## The schema

A page type starts with `smoodly.schema.page()`: a name, a title, and a `zones` map that gives each zone a policy. The schema is the same file in every framework; in an Astro project it lives under `src/components/pages/`.

File: `components/pages/Home.schema.ts`

```ts
import { smoodly, z } from "smoodly";
import { heroSchema } from "../sections/Hero.schema";
// …
export const homeSchema = smoodly.schema.page({
  name: "home",
  title: "Home",
  slug: "home",
  zones: {
    hero: z.locked(heroSchema),
    body: z.freeform({ sections: [imageTextSchema, pointsSchema, favouriteArticlesSchema, peopleSchema, quoteSchema], custom: true }),
  },
  seo: true,
});
```

| Name | Description |
| --- | --- |
| `name` | What a page record stores as its type. Keep it stable once pages exist. |
| `title` | What editors see in the Page type column and when they create a page. |
| `slug` | Makes the page type fixed: one page, at this URL. Leave it out and editors create as many as they like. See below. |
| `zones` | One entry per zone, each with a policy from z. Zones and freedom covers the three. |
| `seo` | `true` gives the page an SEO & Social tab: title, description, social image and a switch to hide it from search engines. |
| `fields` | The page type's own fields, edited on the page's Settings tab. See below. |

## The view

**Astro**

The view is `src/page-types/home.astro`, named after the schema. It receives `page`, `zones` and `head`. Render each zone with `<Zone>` wherever it belongs, among your own markup:

File: `src/page-types/home.astro`

```astro
---
import { Zone } from "smoodly/astro/components";
// …
const { page, zones, head } = Astro.props;
---
<Layout head={head} locale={page.locale} locales={page.locales}>
  <Zone of={zones.hero} />
  <Zone of={zones.body} />
</Layout>
```

`Layout` is the starter's own component: the document, the site header and footer. Anything you render around the zones shows in the canvas but cannot be selected, so editors cannot move or remove it. `head` is what `Head` writes into the document head: the title, the canonical link and the rest.

Register the schema in the `pages` list of `src/smoodly/config.ts`; the view is the file, with nothing else to list:

File: `src/smoodly/config.ts`

```ts
export const config = defineConfig({
  registry: {
    sections,
    // …
    pages: [homeSchema, articlesSchema, pageSchema, newsSchema],
  },
  // …
});
```

**Next.js**

The view lives beside the schema, in `Home.tsx`. It receives `zones` and `page`. Render each zone with `<Zone>` wherever it belongs, among your own JSX:

File: `components/pages/Home.tsx`

```tsx
function HomeView({ zones, page }: Props<typeof homeSchema>) {
  return (
    <PageFrame locale={page.locale} locales={page.locales}>
      <Zone of={zones.hero} />
      <Zone of={zones.body} />
    </PageFrame>
  );
}

export const HomePage = smoodly.page(homeSchema, HomeView);
```

`PageFrame` is the starter's own component: the site header and a `main` element. Anything you render around the zones shows in the canvas but cannot be selected, so editors cannot move or remove it.

Register the schema in the `pages` list of `smoodly/config.ts`, and the component in `pages` in `smoodly/views.ts`:

File: `smoodly/config.ts`

```ts
export const config = defineConfig({
  registry: {
    sections,
    // …
    pages: [homeSchema, articlesSchema, pageSchema, newsSchema],
  },
  // …
});
```

File: `smoodly/views.ts`

```ts
export const views = () =>
  defineViews(config, {
    // …
    pages: [HomePage, ArticlesPage, StandardPage, ArticlePage, NewsPage, NewsPostPage],
    // …
  });
```

## Fixed and open

A page type with a `slug` is **fixed**: it owns exactly one page, at that URL, in every language. Smoodly creates the page the first time the admin loads, so a fresh site has a home page before anyone signs in. Editors can edit it but never create another, rename it, move it or delete it. The slug `home` is special: `homePageSlug` in `defineConfig()` names it, and that page is served at `/`.

A fixed slug can differ per language. The starter's Articles index sits at `/posts` in English and `/artikkelit` in Finnish:

File: `components/pages/Articles.schema.ts`

```ts
export const articlesSchema = smoodly.schema.page({
  name: "articlesIndex",
  title: "Articles",
  slug: { en: "posts", fi: "artikkelit" },
  zones: {
    hero: z.locked(pageHeroSchema),
  },
  seo: true,
});
```

A page type without a `slug` is **open**: editors create as many pages of it as they like, anywhere the page tree allows. When they click *+ New page*, the admin asks which open page type to use. With one open type, as in the starter, it does not ask.

Lorem Co. has three fixed types, Home, Articles and News, and one open type, Page. A fixed page is live as soon as its code is deployed, with empty zones until an editor fills them. Its row appears in *Pages* the next time someone opens the admin. Article and News post are [entry pages](https://smoodly.io/docs/collections/entry-pages.md), which render one entry each.

## The page prop

`page` tells the view where the page sits, so breadcrumbs and sub-navigation need no query:

| Name | Description |
| --- | --- |
| `page.title, page.locale` | The page's title and the language it is rendered in. |
| `page.path, page.url` | The page's URL within the site, and the same address through your framework's locale routing. On a single-language site they are equal. |
| `page.ancestors` | Links to the pages above it, root first. |
| `page.children` | Links to the pages below it. |
| `page.locales` | One key per language: the page's address there, or null where it does not exist or is unpublished. What a language switcher links to. |
| `page.fields` | The page type's own fields, typed from the schema. |

Each link carries `title`, `path`, `url`, `hasPage` and `fields`. A path in the page tree, which groups pages without being one, has `hasPage` false. The starter's Page type uses both lists:

**Astro**

File: `src/page-types/page.astro`

```astro
---
// …
const shown = page.children.filter((c) => c.hasPage && c.fields.showInNavigation === true);
---
<Layout head={head} locale={page.locale} locales={page.locales}>
  {page.ancestors.length > 0 && (
    <nav class="container breadcrumb" aria-label="Breadcrumb">
      {page.ancestors.map((a) => <span>{a.hasPage ? <a href={a.url}>{a.title}</a> : a.title} / </span>)}
      {page.title}
    </nav>
  )}
  {shown.length > 0 && (
    <nav class="container subnav" aria-label="Pages in this section">
      {shown.map((c) => <a href={c.url}>{c.title}</a>)}
    </nav>
  )}
  <Zone of={zones.hero} />
  <Zone of={zones.body} />
</Layout>
```

**Next.js**

File: `components/pages/Page.tsx`

```tsx
function PageView({ zones, page }: Props<typeof pageSchema>) {
  const shown = page.children.filter((c) => c.hasPage && c.fields.showInNavigation === true);
  return (
    <PageFrame locale={page.locale} locales={page.locales}>
      {page.ancestors.length > 0 && (
        <nav className="container breadcrumb" aria-label="Breadcrumb">
          {page.ancestors.map((a) => (
            <span key={a.path}>{a.hasPage ? <Link href={a.url}>{a.title}</Link> : a.title} / </span>
          ))}
          {page.title}
        </nav>
      )}
      {shown.length > 0 && (
        <nav className="container subnav" aria-label="Pages in this section">
          {shown.map((c) => <Link key={c.path} href={c.url}>{c.title}</Link>)}
        </nav>
      )}
      <Zone of={zones.hero} />
      <Zone of={zones.body} />
    </PageFrame>
  );
}
```

## Page fields

A page type can declare fields of its own, for values that belong to the page rather than to a section. The starter's Page type has one:

File: `components/pages/Page.schema.ts`

```ts
export const pageSchema = smoodly.schema.page({
  name: "page",
  title: "Page",
  zones: {
    hero: z.locked(pageHeroSchema),
    body: z.freeform({ sections: [imageTextSchema, pointsSchema, favouriteArticlesSchema, peopleSchema, quoteSchema], custom: true }),
  },
  seo: true,
  fields: { showInNavigation: f.boolean().default(true) },
});
```

Editors find it on the page's *Settings* tab, next to the title and slug. The view reads it as `page.fields.showInNavigation`, and every link in `ancestors` and `children` carries the linked page's fields, which is how the sub-navigation above filters without a query.

Page fields are a settings form, not content: text, link, date, number, boolean, the choice fields, tags, media and objects. Refs, lists and richtext are not allowed, and `.localized()` is not needed because page fields are already stored per language.

Next, [Zones and freedom](https://smoodly.io/docs/content-modeling/zones.md) explains the three policies a zone can have.
