Skip to content

boolean

A boolean field is a simple "True/False" choice. The value stored in the database will be either true or false.

Module field definition

javascript
// Configuring a `isSpecial` field in a module's `fields.add` subsection:
isSpecial: {
  label: 'Is this a special item?',
  type: 'boolean'
}

Settings

Required

PropertyTypeDefaultDescription
labelStringn/aSets the visible label for the field in the UI
typeStringn/aSpecifies the field type (boolean for this type)

Optional

PropertyTypeDefaultDescription
defBooleann/aThe default value for the field
helpStringn/aHelp text for the content editor
htmlHelpStringn/aHelp text with support for HTML markup
ifObject{}Conditions to meet before the field is active. See the guide for details.
requiredIfObject{}Conditions to meet before the field is required. See the guide for details.
hiddenBooleanfalseIf true, the field is hidden
requiredBooleanfalseIf true, the field is mandatory
readOnlyBooleanfalseIf true, prevents the user from editing the field value
toggleBoolean/Objectn/aIf set to true or a configuration object, the field will use an alternate "toggle" interface. See below.

Customizing boolean field labels

We can change labels for the boolean input using a toggle object. The user interface will use the values of true and false properties on the object as labels.

javascript
showRelatedArticles: {
  label: 'Should the page display related articles?',
  type: 'boolean',
  toggle:{
    true: 'Show related articles',
    false: 'Hide related articles'
  }
}

Use in templates

nunjucks
<!-- To print the value: -->
{{ data.piece.isSpecial }}
<!-- or use it in a conditional: -->
<button class="{% if data.piece.isSpecial %}is-special{% endif %}">
  Engage
</button>