# Toggle and Toggle Content Blocks

> The Toggle block (aegis/toggle) is a content switcher: two labeled views, one visible at a time. It is not an accordion. For FAQ expand/collapse, use the Accordion List variation on core/list — see Block variations.

This matches the Gutenberg [Toggle Content](https://wordpress.org/plugins/toggle-content/) pattern (primary / secondary inner content and a pill, switch, or button control).

## Overview

> [!NOTE]
> **Provided by Aegis Dash.** Since Aegis Dash 1.1.0 this block is registered by the plugin. It appears in the inserter once one of its settings is on at **Aegis → Blocks → Toggle**; there is no separate switch for the block itself. A site that already used the block through the Aegis theme has those settings turned on the first time Aegis Dash 1.1.0 loads. The theme only registers its own copy while Aegis Dash is not providing the block. Extras marked Pro need Aegis Pro.

| Block | Name | Role |
| --- | --- | --- |
| Toggle | `aegis/toggle` | Switcher control + two views |
| Toggle Content | `aegis/toggle-content` | One view (`slot` `a` or `b`) |

Toggle Content **only** inserts inside a Toggle block. The inserter template creates both views.

## Toggle attributes

| Attribute | Type | Default | Description |
| --- | --- | --- | --- |
| `switchStyle` | string | `switch` | `pill`, `switch`, or `buttons` (limited to enabled extras) |
| `alignment` | string | `center` | `left`, `center`, or `right` |
| `primaryLabel` | string | empty | Label for view `a` (translated “First” when empty) |
| `secondaryLabel` | string | empty | Label for view `b` (translated “Second” when empty) |
| `initialContent` | string | `a` | Which view is shown first |
| `animationDuration` | number | `300` | Transition duration in ms (pill/switch motion and Pro animations) |
| `allowNested` | boolean | `false` | Allow a Toggle inside Toggle Content (Pro extra `toggle_nested`) |
| `instanceId` | string | empty | Stable id for persist/ARIA, set from the editor `clientId` |

Saved accordion-era Toggle blocks (heading + one content pane) migrate to a switcher: the heading becomes the primary label, existing content becomes view `a`, and an empty view `b` is added. Migration only runs when inner blocks are not already Toggle Content.

## Usage

![A Toggle block in the editor with its switch and the first Toggle Content panel open, and the Toggle Settings in the sidebar.](https://www.atmostfear-entertainment.com/wp-content/uploads/2026/11/toggle-editor.png)

*Each Toggle Content block is one switchable panel.*

1. Enable at least one extra at **Aegis → Blocks → Toggle** (Pill, Switch, or Buttons is enough).
2. Insert the **Toggle** block.
3. Edit the two labels (with Custom Labels on) and add blocks inside each **Toggle Content** view.
4. Click a label to preview the other view in the editor. Selecting a block inside a view also switches the preview to that view.
5. Optionally set alignment and which view is shown first.

## Appearance (light and dark)

Pill, switch, and button styles use Aegis mode tokens so labels stay readable in light and dark:

![The same Toggle block shown in the light and dark styles side by side.](https://www.atmostfear-entertainment.com/wp-content/uploads/2026/11/toggle-light-dark.png)

*Toggle in light and dark mode.*

- Pill chip and switch thumb: `--wp--custom--body--background` (page surface)
- Pill active label: `--wp--custom--body--color`
- Buttons active fill/text: `--wp--custom--button--background` and `--wp--custom--button--color` (same as theme `core/button`)

Do not use WordPress `base` / `contrast` presets — this theme does not define them.

## Aegis → Blocks → Toggle

There is no parent Toggle toggle. Enabling any extra implies the block (same pattern as Related Posts and Slider). Without Aegis Dash (the theme’s own copy), all free extras behave as on. The `aegis/toggle-content` child uses the same parent key.

| Extra | Inspector / render | Off fallback |
| --- | --- | --- |
| `toggle_pill` | Pill switcher style | Style unavailable; another enabled style (or Switch) is used |
| `toggle_switch` | Switch (track + thumb) style | Style unavailable |
| `toggle_buttons` | Separate button style | Style unavailable |
| `toggle_position` | Alignment (`left` / `center` / `right`) | `center` |
| `toggle_labels` | Editable primary and secondary labels | Labels stay “First” / “Second” |
| `toggle_animations` | Animation duration (Pro extra, shown in the free inspector) | `300` ms |

Inspector extras are passed as `window.aegisToggleFeatures` on the block editor script.

## Pro sub-features

**Aegis → Blocks → Toggle** Pro extras (when Aegis Pro is licensed): URL sync (`?param=a` / `b`), state persistence, animations (fade, slide, flip, scale), nested toggles inside Toggle Content, and conditional visibility of other elements. Duration stays on the theme inspector so it is not duplicated in the Pro panel. The inspector reads `window.aegisToggleEditor.features`. Nested Toggle inserts require the extra **and** **Allow Nested Toggles** on that block.

On click, the theme script updates the control and dispatches `aegis:toggle:changed` without swapping panel `.is-active` when a Pro animation class is present. Pro `toggle-view.js` then runs `animateTransition()`. URL init, persist restore, and `prefers-reduced-motion: reduce` swap instantly. A URL param wins over stored state. Nested switcher events are ignored. Persist keys use `data-toggle-id` from the HTML anchor, else saved `instanceId`, else a hash of the block source. Back/forward with URL sync also updates conditional visibility.

FAQ schema is not part of this block. Accordion List has `accordion_faq_schema`.

See [Aegis Dash Block Variations](https://www.atmostfear-entertainment.com/docs/aegis/plugins/dash/block-variations/) and [Pro Block Extensions](https://www.atmostfear-entertainment.com/docs/aegis/plugins/dash/).

## Developer notes

- Source: `src/Blocks/toggle/`, `src/Blocks/toggle-content/`
- Registration: `src/Blocks/BlockRegistrar.php` — directory `toggle-content` maps to parent key `toggle`; extras imply that parent
- Styles compile from `style.scss` via `import './style.scss'` to `style-index.css` (same as Slider)
- Frontend: `view.js` scopes clicks and panel updates to this instance (`:scope > .aegis-toggle__control` / `:scope > .aegis-toggle__panels`), then dispatches `aegis:toggle:changed`. Hidden views use `data-active` / `data-slot` (not a global `:not(.is-active)` hide, which would blank the editor canvas)
- Editor: `templateLock` is off so inner paragraphs stay editable; the parent appender is hidden so a third view is not offered. Selecting inner content switches only the Toggle that owns that Toggle Content
- Duration is output as `--aegis-toggle-duration` and `--toggle-animation-duration` on the wrapper
- Dynamic render via `render.php`

## Next Steps

- [Custom Blocks](https://www.atmostfear-entertainment.com/docs/aegis/plugins/dash/custom-blocks/) — Block index
- [Block variations](https://www.atmostfear-entertainment.com/docs/aegis/themes/theme/block-variations/#accordion-list) — FAQ accordion
- [Accessibility](https://www.atmostfear-entertainment.com/docs/aegis/themes/theme/accessibility/) — Switcher keyboard support

---

Source: https://www.atmostfear-entertainment.com/docs/aegis/plugins/dash/toggle/ · Updated 2026-11-22
