Standard toggles
Creating toggles within your article content doesn’t involve copying and pasting any HTML as the Tabs extension lets you transform standard ordered (<ol>
) and unordered (<ul>
) lists created in the article editor into interactive collapsible and expandable sections. This makes it easy for visitors to find what they’re looking and allows content creators to focus on producing helpful content.
If you do ever need to migrate your content you can do so without having to worry about unnecessary markup or inline styles.
The default template is simple, elegant and responsive and will automatically inherit the overall style of your theme. You can add any type of content you like to each collapsible section, including HTML, images, videos and other article formatting styles.
Customized toggles
Using the options described on the Usage tab you can have the toggles behave an an accordion, where only one toggle can be expanded at a time, and create custom templates. Custom templates can be used to change completely change the look-and-feel of the toggles, add new elements like icons and even modify the behavior of the toggles themselves.
Creating toggles
Toggles can be used anywhere in the help center, but often they are used within article content. Our extension allows you to create toggles in several different ways, none of which require you to copy-and-paste any HTML.
The Toggles extension is bundled into all of our themes by default, so you can start using it straight away. The source code can be found within the extensions.(min.)js
file in the theme’s Assets folder.
When creating or updating an article using the Zendesk article editor:
-
Create a numbered () or bulleted list () using the editor toolbar and add the content that you’d like to see in each tab within the list items.
-
Click the Source Code () button in the editor toolbar to view the source code of the page.
-
Add a class name of
.js-toggles
to the list element to convert it into a set of interactive tabs. -
Add a
title
attribute to each list item containing the title you’d like to use for the tab. Alternatively, you can apply a class name of.toggle-heading
to an element within the list item and that element’s text content will be used as the tab title.<ul class="js-toggles"> <li title="The first toggle title">...</li> <li title="The second toggle title">...</li> <li> <h3 class="toggle-heading">The third toggle title</h3> ... </li> </ul>
The Toggles extension allows you to convert a standard ordered (<ol>
) or unordered (<ul>
) list into an interactive set of tabs using JavaScript:
<ul class="my-toggles">
<li title="The first toggle">...</li>
<li title="The second toggle">...</li>
<li title="The third toggle">...</li>
</ul>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
const toggles = [...document.querySelectorAll('.my-toggles')]
toggles.forEach(el => {
new Toggles(el, {
// Options go here
})
})
})
</script>
Options
Options can be passed via data attributes or JavaScript.
Name | Type | Default | Description |
---|---|---|---|
initial | number | -1 | The index of the toggle to open on initialization. |
accordion | boolean | false | True if the toggle group should behave as an accordion. |
activeClass | string | 'text-primary' | The class name(s) to apply to an active toggle heading. |
template | string null | null | The name of the template to use. |
templateData | object | {} | Additional data to provide to the template rendering function. |
For data attributes, append the option name to data-
and use kebab case instead of camel case.
Events
Class | Properties |
---|---|
toggles:render | Fires when the toggles markup has been rendered and inserted into the DOM. |