Toggle Field Type

Renders a toggle control inside the block.

The type we would use inside the schema’s field_meta property to render this field is “toggle”: "type": "toggle"

If you haven’t already, we suggest you read the “model.json file” and “Field Types” pages before continuing.

Minimum Schema needed to create the field

"should_show_title": {
  "type": "object",
  "field_meta": {
    "type": "toggle",
    "label": "Toggle the Title"
  },
  "default": {
    "checked": false
  }
}

This snippet of code will generate a simple toggle control for managing boolean data. The field name will be “should_show_title”, its label will be “Toggle the Title” and it will be false by default.

What it would look like inside the block in the editor.

Toggle Field Type example | theme-redone

Rendering field’s data on the front-end:

We would use the same property that’s present inside the “default” object; "checked", in this case.
In latte, it would look something like this.

{if $should_show_title['checked']}
  <h3>This is a Title</h3>
{/if}

Or, even shorter, like this:

<h3 n:if="$should_show_title['checked']">This is a Title</h3>

Additional / Optional field_meta properties

Besides the optional properties help (explained on Field Types page), and col (explained on model.json page), this field type doesn’t have its own optional properties at this point.

The Toggle Field Type is identical and behaves the same as the Checkbox Field Type. The only difference is how it looks inside the block

Join Our Newsletter

To get updates about Theme Redone