Components
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.
Overview
Each framework has its own import path:
| Component | Renders | Astro | Vue | React |
|---|---|---|---|---|
Image | an image field as <img> | yes | yes | yes |
Picture | other images per screen | yes | yes | yes |
Link | a link field as <a> | yes | yes | yes |
Blocks | a blocks field | yes | yes | yes |
Richtext | a rich text field as HTML | yes | yes | yes |
Seo | the tags in <head> | yes | – | yes |
- Astro:
tenoncms/astro/components - Vue:
tenoncms/vue. Nuxt imports them for you with the prefixTenon:TenonImage,TenonPicture,TenonLink,TenonBlocksandTenonRichtext. For head tags, Nuxt hasuseTenonSeo(). - 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:
assets the element, likeas="article". In Vue and React, it can also be a component.asChildrenders no element of its own. The props go on the only child instead. Astro has noasChild.
<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" />
<template>
<TenonImage :image="post.cover" sizes="(min-width: 720px) 720px, 100vw" />
</template>
import { Image } from "tenoncms/react";
<Image image={post.cover} sizes="(min-width: 720px) 720px, 100vw" />;
Image renders nothing.alt is empty."lazy". For the main image at the top of a page, pass loading="eager" and fetchpriority="high".All other attributes go on the <img>.
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"
/>
<template>
<TenonPicture
:image="page.hero"
:sources="[{ media: '(max-width: 600px)', image: page.heroMobile }]"
sizes="100vw"
/>
</template>
import { Picture } from "tenoncms/react";
<Picture
image={page.hero}
sources={[{ media: "(max-width: 600px)", image: page.heroMobile }]}
sizes="100vw"
/>;
Picture renders nothing.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,loadingandclass, go on the<img>.
Link
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>
<template>
<TenonLink :link="page.cta" class="button">Read more</TenonLink>
</template>
import { Link as RouterLink } from "@tanstack/react-router";
import { Link } from "tenoncms/react";
<Link link={page.cta} as={RouterLink} className="button">
Read more
</Link>;
- For an empty link, or a link to a deleted page,
Linkrenders nothing. - With a router component in
as, internal paths like/aboutgo to it asto, so they navigate without a reload. Other URLs, likehttps://…ormailto:, render a plain<a>. - In Nuxt,
TenonLinkusesNuxtLink, so internal links prefetch. - In Astro,
Linkalways 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 }} />
<script setup lang="ts">
import Hero from "~/components/blocks/Hero.vue";
import Text from "~/components/blocks/Text.vue";
</script>
<template>
<TenonBlocks :blocks="page.content" :components="{ hero: Hero, text: Text }" />
</template>
import { Blocks } from "tenoncms/react";
import { Hero } from "../blocks/Hero";
import { Text } from "../blocks/Text";
<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>
<!-- app/components/blocks/Hero.vue -->
<script setup lang="ts">
const props = defineProps<{ block: { id: string; title: string } }>();
const edit = useBlockEdit(props.block);
</script>
<template>
<h2 :data-cms="edit('title')">{{ block.title }}</h2>
</template>
// src/blocks/Hero.tsx
import type { BlockProps } from "tenoncms/react";
export function Hero({ block, edit }: BlockProps<{ title: string }>) {
return <h2 data-cms={edit("title")}>{block.title}</h2>;
}
- For a global,
idisnull. For a field inside a group,pathis a dot path, likelayout.content. edit()without a path marks the whole block.- Without
editonBlocks,edit()returnsundefinedand marks nothing. - In Vue outside Nuxt, import
useBlockEditfromtenoncms/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" />
<template>
<TenonRichtext :content="post.body" class="prose" as="article" />
</template>
import { Richtext } from "tenoncms/react";
<Richtext content={post.body} className="prose" />;
contentcan benullorundefined.- Read the field with
populate, the default, so links and images have their current URLs. The component fetches nothing. assets the outer element. The default isdiv.- Outside these frameworks,
renderRichtext(content)fromtenoncms/richtextreturns 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>
<script setup lang="ts">
await useTenonSeo(page);
</script>
import { Seo } from "tenoncms/react";
<Seo page={page} general={general} seo={seo} site={site} />;
populate: { seo: { image: true } } for the share image, and with alternates: true for the hreflang tags.general settings. Astro reads them in the page's language when you leave them out.seo settings. Astro reads them in the page's language when you leave them out.site.url of your config.- In React, the component has no CMS of its own. Read
general,seoandcms.site.urlin 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'shead()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:
| Helper | Returns |
|---|---|
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}
Related resources
- Media: image sizes, formats and providers.
- Pages and SEO: head tags, sitemap and settings.
- Live preview: mark elements for click-to-edit.