__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
---
layout: docs
title: "Toggle input"
date: 2022-01-17T00:00:00+01:00
draft: false
weight: 60
tags:
- MDL-73470
- 4.0
---
## How to use
Toggle input is rendered using a template found in lib/templates/toggle.mustache.
The parameters for the template context are:
* id: Unique id for the toggle input.
* extraclasses: Any extra classes added to the toggle input outer container.
* checked: If the initial status is checked.
* disabled: If toggle input is disabled.
* dataattributes: Array of name/value elements added as data-attributes.
* title: Title text.
* label: Label text.
* labelclasses: Any extra classes added to the label container.
## Examples
<div class="small">
Checked toggle and with "sr-only" label.
</div>
{{< mustache template="core/toggle" >}}
{
"id": "example-toggle-1",
"checked": true,
"dataattributes": [{
"name": "action",
"value": "toggle-status"
}],
"title": "Toggle Enabled",
"label": "Enable/disable status",
"labelclasses": "sr-only"
}
{{< /mustache >}}
<div class="mt-3 small">
Disabled toggle with extra classes.
</div>
{{< mustache template="core/toggle" >}}
{
"id": "example-toggle-2",
"disabled": true,
"extraclasses": "mt-2 ms-2",
"dataattributes": [{
"name": "action",
"value": "toggle-status"
}],
"title": "Toggle Disabled",
"label": "Enable/disable status"
}
{{< /mustache >}}
## Use toggle as a template block
It is also possible to include *core/toggle* in any other template using [blocks](https://moodledev.io/docs/guides/templates#blocks), instead of rendering it with a context.
The parameters that you can define are:
* id: Unique id for the toggle input.
* extraclasses: Any extra classes added to the toggle input outer container.
* attributes: Any attributes added to the toggle input.
* data-attributes
* checked
* disabled
* labelmarkup: Label element code block.
* Should include *class="custom-control-label"*.
* title: Title text.
* label: Label text.
* labelclasses: Any extra classes added to the label container.
<div class="small">
Example of template using toggle as a block.
</div>
{{< mustache template="tool_componentlibrary/examples/toggle/example" >}}
{
}
{{< /mustache >}}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| _index.md | File | 85 B | 0777 |
|
| actionmenu.md | File | 6.39 KB | 0777 |
|
| activityicons.md | File | 8.38 KB | 0777 |
|
| buttons.md | File | 5.9 KB | 0777 |
|
| coursecards.md | File | 6.26 KB | 0777 |
|
| dom-modal.md | File | 4.29 KB | 0777 |
|
| dropdowns.md | File | 13.23 KB | 0777 |
|
| dynamictabs.md | File | 2.87 KB | 0777 |
|
| example.md | File | 1.52 KB | 0777 |
|
| footer.md | File | 1.49 KB | 0777 |
|
| form-elements.md | File | 1.08 KB | 0777 |
|
| moodle-icons.md | File | 1.71 KB | 0777 |
|
| notifications.md | File | 2.55 KB | 0777 |
|
| search-input.md | File | 3.42 KB | 0777 |
|
| showmore.md | File | 1.18 KB | 0777 |
|
| toggle.md | File | 2.29 KB | 0777 |
|