Boolean and select
The boolean field and the select field (one option or several from a declared list, each option with a stable id and per-locale label), with parameters, validation, stored values and what templates receive.
boolean
True or false: dog friendly, step-free, featured. Held once for every locale.
fields:
- { name: dogFriendly, type: boolean, index: true, label: { en-GB: Dogs welcome } } A boolean has no parameters of its own, and an unset boolean is false in a template. It has no validation of its own, and required on a boolean does not force it to be true: use a validation rule (agreed == true) for that.
The stored value is a JSON true or false, and a template receives the boolean:
{% if entry.dogFriendly %}<p>Dogs welcome</p>{% endif %} A boolean cannot be unique. In an expression it is compared with true or false: dogFriendly == true.
select
One value, or several with multiple: true, from a list the schema declares.
fields:
- name: difficulty
type: select
required: true
index: true
options:
- { value: easy, label: { en-GB: Easy, cy-GB: Hawdd } }
- { value: moderate, label: { en-GB: Moderate, cy-GB: Cymedrol } }
- { value: hard, label: { en-GB: Hard, cy-GB: Anodd } }
- name: facilities
type: select
multiple: true
index: true
options:
- { value: parking, label: { en-GB: Parking } }
- { value: wifi, label: { en-GB: Wi-Fi } }
- { value: stepFree, label: { en-GB: Step-free access } } Parameters
| Parameter | Type | Default | What it does |
|---|---|---|---|
options | list | required | The choices. Each is a mapping { value, label }, or a bare string that is both value and label. |
options[].value | string | What is stored and what templates and expressions compare against. | |
options[].label | locale map | the value | What editors and visitors read, per locale. |
options[].id | string | written by check --fix | The option’s stable id (opt_...). A bare-string option is rewritten as { value, id } by check --fix. |
multiple | boolean | false | Holds a list of values. |
Give every option a label as a locale map. A template’s label reads the label for the request locale from the map, and falls back to the value when there is none.
engine-dmo check warns when an option’s label map lacks an enabled locale (the label of option hard has no translation for cy), but says nothing about an option with no label at all, or one whose label is a plain string. A plain-string label passes check, but a template’s .label prints the value instead. engine-dmo dev field add --options a,b,c writes options with no labels; add label: { en: ... } to each, keeping its id:.
Validation
| Code | Message |
|---|---|
option | “x” is not one of the options |
An expression that compares a select with a value it does not offer fails engine-dmo check with the options listed: visible_when: "tlak" is not an option of kind.
Stored value
Seed files, imports, the content API and templates use the option’s value: a string, or a list of strings with multiple. Internally the engine stores the option’s id, so renaming a value (keeping its id) keeps every document’s choice, and the schema plan shows it as a rename. Removing an option that documents hold is a destructive change (Schema changes).
Template value
A single select is an option with value and label, or nothing when empty. A multiple select is a list of them, in the order chosen.
<dd class="difficulty-{{ entry.difficulty.value }}">{{ entry.difficulty.label }}</dd>
{% if entry.facilities %}
<ul>{% for f in entry.facilities %}<li>{{ f.label }}</li>{% endfor %}</ul>
{% endif %} engine-dmo dev option add <type> <field> <value> adds an option with its id. A select reads an old text value exactly when it is one of the options; a value that is not is kept and flagged for a person to decide.
Numbers and money
The number field (min, max, step, integer, display unit) and the money field (a decimal amount with its ISO 4217 currency, fixed or chosen), with parameters, validation, stored shapes and template values.
Dates and times
The date field (a calendar day), the datetime field (a wall-clock time in an IANA zone with its UTC instant) and the recurrence field (an event's repeating schedule and its occurrences), with parameters, stored shapes and template values.