Checkbox Field Type
Renders a checkbox control inside the block.
The type we would use inside the schema’s field_meta property to render this field is “checkbox”: "type": "checkbox"
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": "checkbox",
"label": "Toggle the Title"
},
"default": {
"checked": false
}
}
This snippet of code will generate a simple checkbox 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.
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.