<cv-toggle>
<div data-cv-toggle="category">
Toggles let you show or hide sections of a page based on a category (for example: mac, linux, windows). They are ideal for platform-specific content, progressive disclosure, or audience-targeted sections.
CODE:
<section data-cv-toggle="mac">
<h2>macOS</h2>
<p>macOS-specific install steps...</p>
</section>
<section data-cv-toggle="linux">
<h2>Linux</h2>
<p>Linux-specific install steps...</p>
</section>
<section data-cv-toggle="windows">
<h2>Windows</h2>
<p>Windows-specific install steps...</p>
</section>
OUTPUT:
When the active toggle state includes mac, only the element with data-cv-toggle="mac" will be visible. CustomViews applies .cv-visible and .cv-hidden classes to animate visibility transitions.
Other attribute names are supported as well:
data-customviews-togglebehaves the same asdata-cv-toggle.
You can apply multiple toggles to a single element by separating categories with spaces. This allows content to appear as long as one toggle category is active.
<div data-cv-toggle="mac linux">
This section appears for both macOS and Linux users.
</div>
<cv-toggle category="mac linux">
This section appears for both macOS and Linux users.
</cv-toggle>
To make toggles discoverable by the CustomViews widget, you must define them in your customviews.config.json.
{
"config": {
"allToggles": ["mac", "linux", "windows"],
"defaultState": {
"toggles": ["mac", "linux", "windows"]
}
}
}
| Field | Description |
|---|---|
config.allToggles | List of all toggle IDs the site supports. The widget uses this list to render toggle controls. |
config.defaultState.toggles | Toggles visible by default on first load when no URL or stored state is available. |
| Name | Type | Default | Description |
|---|---|---|---|
data-cv-toggle | string | required for data attribute usage | Defines the category for the element. Example: data-cv-toggle="mac". |
category | string | required for <cv-toggle> | Defines the category for the cv-toggle element. Example: category="mac". |
data-cv-id / data-customviews-id | string | - | Marks the element as an asset render target. When visible, matching assets from assets.json will be dynamically inserted. |
showUrl is enabled)config.defaultState)Elements whose toggles match the active state are shown; all others are hidden.
Toggles not appearing in widget?
No effect when toggling?
URL state not persisting in URL bar?
Widget not loading?