Skip to content

View Modes Data

Switch to Zen Mode

Starlight View Modes exposes information about the view modes in your project. This guide explains how to use Starlight View Modes’ data.

Similar to Starlight route data, the route data provided by the Starlight View Modes is an object containing the information about all the view modes available for the current page. It includes information like a list of all the modes, the name of each mode, and in which mode the current page is.

To learn more about all the available properties in the route data object, check the starlightViewModes section.

You can access the route data object provided by the Starlight View Modes plugin from the Astro.locals.starlightViewModes global in Astro components:

example.astro
---
const { modes } = Astro.locals.starlightViewModes
// ^ The list of all the modes in your project.
---

This can be useful for example to render a list of all view modes that link to the same page in that mode:

ViewModes.astro
<ul>
{
Astro.locals.starlightViewModes.modes.map((mode) => (
<li>
<a href={mode.href} view-modes-ignore>
{mode.title}
</a>
</li>
))
}
</ul>

The starlightViewModes object has the following properties:

A list of all the available view modes of the current page.

Each modes object has the following properties:

type: string

The name of the view mode.

type: string

The name of the view mode in readable form.

type: string

The link to the same page in this view mode.

type: boolean

Indicates if the current page is in this view mode right now.

type: string

The activation or deactivation SVG path of the view mode, depending on the current mode. The default mode has no icon (undefined).