CMS Configuration
Themes are managed in CMS and can be assigned to both pages and individual blocks.
Theme Data Structure
Each theme in CMS consists of:
- name (string, required) – theme name, which must match the CSS class name (e.g.,
dark→.theme-dark) - logo (Media, optional) – logo assigned to the theme
The theme name is crucial – it must exactly match the CSS class name defined in theme.css (without the theme- prefix).
Strapi
Adding a Theme in Strapi
- Go to Content-Type Builder in Strapi
- Find the AppConfig content type
- In the Themes field (relation) add a new entry of type Theme
- Fill in the fields:
- Name – theme name (e.g.,
dark,corporate) - Logo (optional) – select media with the logo
- Name – theme name (e.g.,
- Save changes
Structure in Strapi
Themes are stored as a relation in the AppConfig content type:
appConfig {
themes {
name // e.g., "dark"
logo // Media (optional)
}
}
Mapping from Strapi to the application model happens in:
themes: component.themes.reduce((prev, theme) => {
return {
...prev,
[theme.name]: {
name: theme.name,
logo: mapMedia(theme.logo, baseUrl),
},
};
}, {}),
Assigning Theme to Page
- Open a page in Strapi
- In the Theme field, select a theme from the list of available themes
- Save and publish the page
Assigning Theme to Block
- Open a block in Strapi
- In the Layout section, find the Theme field
- Select a theme from the list of available themes
- Save and publish the block
Contentful
Adding a Theme in Contentful
- Go to Content model in Contentful
- Find the AppConfig content type
- In the Themes field (reference, many) add a new entry of type Theme
- Fill in the fields:
- Name – theme name (e.g.,
dark,corporate) - Logo (optional) – select asset with the logo
- Name – theme name (e.g.,
- Save and publish changes
Structure in Contentful
Themes are stored as a reference collection in the AppConfig content type:
appConfig {
themesCollection {
items {
name // e.g., "dark"
logo // Asset (optional)
}
}
}
Mapping from Contentful to the application model happens in:
themes:
appConfig.themesCollection?.items.reduce((prev, theme) => {
if (!theme.name) return prev;
return {
...prev,
[theme.name]: {
name: theme.name,
logo: mapMedia(theme.logo, baseUrl),
},
};
}, {} as CMS.Model.AppConfig.Themes) || {},
Assigning Theme to Block
- Open a block in Contentful
- In the Layout section, find the Theme field
- Select a theme from the list of available themes
- Save and publish the block
The theme is mapped from the block's layout section:
const mapLayout = ({ spacing, background, variant, theme }: ComponentBaseFragment): CMS.Model.Page.LayoutSection => {
return {
spacing: spacing as CMS.Model.Page.LayoutSection['spacing'],
background: background as CMS.Model.Page.LayoutSection['background'],
variant: variant as CMS.Model.Page.LayoutSection['variant'],
theme: theme as CMS.Model.Page.LayoutSection['theme'],
};
};
Important Notes
Theme Name
The theme name in CMS must match the CSS class name in theme.css:
- CMS:
dark→ CSS:.theme-dark - CMS:
corporate→ CSS:.theme-corporate
If the names don't match, the theme will not be applied correctly.
Theme Availability
All themes defined in CMS are available in GlobalProvider through themes.available:
const { themes } = useGlobalContext();
// themes.available - object with all themes
// themes.current - current page theme
Theme Hierarchy
If a block has an assigned theme, it overrides the page theme for that specific block. If a block doesn't have an assigned theme, it inherits the page theme (or the default theme from :root).
Next Steps
- See how to define themes in CSS