Components

ContentRenderer

Takes your component from an AST to a wonderful template.

The <ContentRenderer> component renders a document coming from a query with queryCollections().

This component only works with the pages collection.

Props

PropDefaultTypeDescription
value{}ParsedContentThe document to render.
tag'div'stringThe tag to use for the renderer element if it is used.
excerptfalsebooleanWhether to render the excerpt only without the rest of the content.
components{}objectThe map of custom components to use for rendering. This prop will pass to the markdown renderer and will not affect other file types.
data{}object (required)A map of variables to inject into the markdown content for later use in binding variables.
proseundefinedbooleanWhether or not to render Prose components instead of HTML tags.
classundefinedstring or objectRoot tag to use for rendering.
unwrapfalseboolean or stringTags to unwrap separated by spaces. Example: 'ul li'.

Example Usage

pages/[...slug].vue
<script lang="ts" setup>
const route = useRoute()
const { data: page } = await useAsyncData(route.path, () => {
  return queryCollection('docs').path(route.path).first()
})
</script>

<template>
  <ContentRenderer v-if="page" :value="page" />
</template>

Handling Missing Pages

If the queried content is missing, you can display a custom fallback message.

pages/[...slug].vue
<script lang="ts" setup>
const route = useRoute()
const { data: page } = await useAsyncData(route.path, () => {
  return queryCollection('docs').path(route.path).findOne()
})
</script>

<template>
  <template v-if="page">
    <ContentRenderer :value="page" />
  </template>
  <template v-else>
    <div class="empty-page">
      <h1>Page Not Found</h1>
      <p>Oops! The content you're looking for doesn't exist.</p>
      <NuxtLink to="/">Go back home</NuxtLink>
    </div>
  </template>
</template>

Handling Empty Pages

If the queried content is empty, you can display a custom fallback message.