<Slot>

Learn how to render the content of a slot using components.

This component fetches and renders the content of a Slot with full server-side rendering support, serving as the declarative equivalent of the useContent composable.

Example

Here is a basic example of how to use this component:

components/HomeHero.vue
123456789
<template>  <Slot id="home-hero" v-slot="{ content }">    <div>      <strong>{{ content.title }}</strong>      <p>{{ content.subtitle }}</p>      <a :href="content.button.link">{{ content.button.label }}</a>    </div>  </Slot></template>

Loading and error states

You can use named slots to handle loading and error states:

components/HomeHero.vue
12345678910111213141516171819
<template>  <Slot id="home-hero">    <template #default="{ content }">      <div>        <strong>{{ content.title }}</strong>        <p>{{ content.subtitle }}</p>        <a :href="content.button.link">{{ content.button.label }}</a>      </div>    </template>
    <template #loading>      <p>Loading...</p>    </template>
    <template #error="{ error }">      <p>Something went wrong: {{ error.message }}</p>    </template>  </Slot></template>

Props

The following list describes the supported props:

id
string

The ID of the slot to fetch, optionally followed by a version number. For example, home-hero@2.

fallback(optional)
JSON

A fallback value to render in case of an error.

If not specified, the #error slot renders on failure.

preferredLocale(optional)
string

The locale code to fetch the content.

The code consists of a two-part string that specifies the language and, optionally, the country. For example, en represents English, en-us stands for English (United States), and pt-br for Portuguese (Brazil). It is case-insensitive and supports both hyphens and underscores as separators to accommodate the different conventions used by browsers, libraries, and other systems.

If no content is available in the preferred locale, the default locale content is returned instead.

Default:default locale
timeout(optional)
number

The maximum fetch time in milliseconds.

Once reached, the SDK will abort the request and reject the promise with a timeout error.

attributes(optional)
object

The map of attributes to inject in the evaluation context.

The attributes can be referenced in audience conditions using the context variable. For example, suppose you pass the following attributes:

{cities: ["New York", "San Francisco"]}

You can then reference them in queries like:

context's cities include location's cityName

For more information, see Context variables.

The following restrictions apply to the attributes:

  • Up to 30 entries and 5 levels deep
  • Keys can be either numbers or non-empty strings with a maximum length of 50 characters
  • Values can be null, numbers, booleans, strings (up to 50 characters), or nested maps
  • Nested maps follow the same constraints for keys and values

Slots

The following list describes the supported slots:

#default
object

Renders when the content has been fetched successfully.

The scope exposes content with the slot content, and an optional metadata object.

#loading
object

Renders while the content is being fetched.

#error
object

Renders when fetching fails. Not used when a fallback prop is provided.

The scope exposes error with the error details.