API Reference: ToggleAttribute Class

The ToggleAttribute can be applied to content model properties. The attribute specifies that a toggle switch should be rendered for this property in the back office. The toggle switch is the same component as the checkbox editor but styled as a toggle switch instead of a checkbox control.

Usage

Decorate the content model property with the ToggleAttribute. See the Checkbox Editor page for more information on how to configure the toggle switch editor. Toggle switch editors can be used for all value type properties, not only boolean.

Example

[Page]
public class ContentPage: IContentType
{
    // Render toggle switch for boolean property.
    [Toggle(OnLabel = "ON", OffLabel = "OFF")]
    public bool DisplayHeader { get; set; }

    // Render toggle switch for string property.
    [DisplayName("Dark mode")]
    [Toggle(CheckedValue = "bg-dark", UncheckedValue = "bg-light", OnLabel = "Yes", OffLabel = "No")]
    public string CssClass { get; set; }
}