getSlotContent

Learn how to synchronously retrieve default slot content.

This function synchronously retrieves the default content for a Slot from the @croct/content package.

Croct's mascot winking
Lazy loading

When using bundlers that support code splitting, prefer the async counterpart over this function, as it enables lazy loading of content modules.

Signature

This function has the following signature:

getSlotContent(slotId: string, language?: string): JsonObject | null

The return is the content as a JSON object, or null if no content is available for the given slot and locale.

Example

Here is a minimal example of how to use this function:

1234567
import {getSlotContent} from '@croct/content';
const content = getSlotContent('home-hero');
if (content !== null) {  console.log(content.title);}

Parameters

The following list describes the supported parameters:

slotId
string

The slot identifier, for example home-hero.

language(optional)
string

The locale code, for example en. If omitted, defaults to the project's default locale.