Building Your Site

Components

Unstyled components that render content in Astro, Vue and React.

Most fields render as plain text or can be used as values. But some need more and it would be painful if yu had to build your own every time. An image needs srcset or alt, a link needs the URL of the page it points to, and a blocks field needs a component per block type. Tenon has a component for each. They add no styles and no classes, so your own CSS decides the look.

If you ever need to see how to build a component, you can look in the repository how these defaults are built.

Overview

Each framework has its own import path:

ComponentRendersAstroVueReact
Imagean image field as <img>yesyesyes
Pictureother images per screenyesyesyes
Linka link field as <a>yesyesyes
Blocksa blocks fieldyesyesyes
Richtexta rich text field as HTMLyesyesyes
Seothe tags in <head>yes–yes
  • Astro: tenoncms/astro/components
  • Vue: tenoncms/vue. Nuxt imports them for you with the prefix Tenon: TenonImage, TenonPicture, TenonLink, TenonBlocks and TenonRichtext. For head tags, Nuxt has useTenonSeo().
  • React: tenoncms/react. The components use no hooks, so they also work as server components.

Link, Blocks and Richtext render one element. Attributes like class go on that element:

  • as sets the element, like as="article". In Vue and React, it can also be a component.
  • asChild renders no element of its own. The props go on the only child instead. Astro has no asChild.
<TenonRichtext :content="post.body" as="article" class="prose" />

<TenonLink :link="page.cta" as-child>
  <button class="button">Read more</button>
</TenonLink>

All components read fields as a read returns them by default, with relations and images loaded. They fetch nothing themselves.

Image

Image renders an image field as an <img> with src, srcset, width, height and alt:

---
import { Image } from "tenoncms/astro/components";
---

<Image image={post.cover} sizes="(min-width: 720px) 720px, 100vw" />
The image field. For an empty field, Image renders nothing.The width the image renders at. Without it, the browser assumes the full screen width and can load a larger file than it needs.Replaces the alt text from the media library. Without either, alt is empty.Default "lazy". For the main image at the top of a page, pass loading="eager" and fetchpriority="high".

All other attributes go on the <img>.

In Astro, Image has the same name as the component of astro:assets. To use both, rename one: import { Image as CmsImage } from "tenoncms/astro/components".

Picture

Picture shows another image when a media query matches, like a tall crop on phones. It renders a <picture> with one <source> per entry of sources, then the <img>:

---
import { Picture } from "tenoncms/astro/components";
---

<Picture
  image={page.hero}
  sources={[{ media: "(max-width: 600px)", image: page.heroMobile }]}
  sizes="100vw"
/>
The image when no source matches. Without it, Picture renders nothing.The other images, each with its media query. A source without an image is left out. sizes defaults to the one of the <img>.
  • Each <source> gets the width and height of its image, so the page keeps the right space for it before it loads.
  • Other attributes, like alt, loading and class, go on the <img>.

Link renders a link field. The content is the link's text. Without it, Link shows the title of the page it points to.

---
import { Link } from "tenoncms/astro/components";
---

<Link link={page.cta} class="button">Read more</Link>
  • For an empty link, or a link to a deleted page, Link renders nothing.
  • With a router component in as, internal paths like /about go to it as to, so they navigate without a reload. Other URLs, like https://… or mailto:, render a plain <a>.
  • In Nuxt, TenonLink uses NuxtLink, so internal links prefetch.
  • In Astro, Link always renders an <a>.
  • A link that opens in a new tab gets rel="noopener noreferrer".

Blocks

Blocks renders a blocks field with one component per block type:

---
import { Blocks } from "tenoncms/astro/components";
import Hero from "../blocks/Hero.astro";
import Text from "../blocks/Text.astro";
---

<Blocks blocks={page.content} components={{ hero: Hero, text: Text }} />

Each component gets the item as its block prop. A block type without a component renders nothing.

Click-to-edit inside blocks

In the live preview, editors click a text on the page to edit it. For fields inside blocks, pass edit to Blocks. It names the document and the field that holds the blocks:

<TenonBlocks
  :blocks="page.content"
  :components="{ hero: Hero, text: Text }"
  :edit="{ collection: 'pages', id: page.id, path: 'content' }"
/>

Each block component then marks its own fields:

---
// src/blocks/Hero.astro
const { block, edit } = Astro.props;
---

<h2 data-cms={edit("title")}>{block.title}</h2>
  • For a global, id is null. For a field inside a group, path is a dot path, like layout.content.
  • edit() without a path marks the whole block.
  • Without edit on Blocks, edit() returns undefined and marks nothing.
  • In Vue outside Nuxt, import useBlockEdit from tenoncms/vue.

Richtext

Richtext turns a rich text field into HTML. It renders on the server, adds no styles and loads no editor:

---
import { Richtext } from "tenoncms/astro/components";
---

<Richtext content={post.body} class="prose" />
  • content can be null or undefined.
  • Read the field with populate, the default, so links and images have their current URLs. The component fetches nothing.
  • as sets the outer element. The default is div.
  • Outside these frameworks, renderRichtext(content) from tenoncms/richtext returns the same HTML as a string.

Your own nodes

A feature you add yourself, like a notice box, needs a renderer on the site too. Pass its Tiptap extension in extensions, keyed by the feature name. The extension's renderHTML decides the markup:

<Richtext content={post.body} extensions={{ notice: [Notice] }} />

The extension MUST work without a browser DOM. To add the feature to the editor, see Rich text extensions.

Seo

Seo puts the title, description, Open Graph, robots, canonical and hreflang tags of a page into <head>. Head tags explains where each value comes from.

---
import { Seo } from "tenoncms/astro/components";
---

<head>
  <Seo page={page} />
</head>
The document the page shows. Read it with populate: { seo: { image: true } } for the share image, and with alternates: true for the hreflang tags.The general settings. Astro reads them in the page's language when you leave them out.The seo settings. Astro reads them in the page's language when you leave them out.The title and description templates of the collection. See Templates per collection.The base of absolute URLs. Astro defaults to site.url of your config.
  • In React, the component has no CMS of its own. Read general, seo and cms.site.url in a server loader and pass them. React 19 moves the tags into <head> from anywhere in the tree.
  • With TanStack Router, seoHead() in the route's head() is the better fit. See Render pages.

Your own components

For Svelte, Solid or your own markup, tenoncms/components has the helpers the components use:

HelperReturns
imageAttrs(image, attrs?)The <img> attributes, or undefined for an empty field
pictureAttrs(image, sources?, attrs?){ sources, img } for a <picture>
linkAttrs(link, router?)href (or to with router), target and rel, or undefined
editBlock(edit, blocks, block, path?)The data-cms value of a field inside a block
<script>
  import { imageAttrs } from "tenoncms/components";
  let { post } = $props();
</script>

{#if post.cover}<img {...imageAttrs(post.cover, { sizes: "100vw" })} />{/if}