{fieldoptions:slice_id:field_id:values}

Description

Renders the HTML option tags for a field that has a defined set of allowed values - a select, checkbox, radio or multiselect widget, or a field whose options come from a constant group or a linked slice. Each allowed value becomes one option element. Pass the current value(s) in the third parameter to mark them as selected: a single value as plain text, or several values as a JSON array for multi-value fields. A field with no enumerable options - a plain text field, an unknown field id, or a field whose value list is empty - yields an empty string. Typically used to build or refresh a select box, for example in an AJAX-driven form.

Parameters

slice_id required default (current item's slice)

The 32-character id of the slice that owns the field. If left empty, the field is looked up in the slice of the current item; outside an item context an empty slice_id yields no output.

field_id required

The id of the field whose allowed values are rendered, for example category........ or a custom select/checkbox field. The field must have an enumerable widget (select, checkbox, radio, multiselect, or one backed by a constant group or a linked slice); a plain text field or an unknown id produces an empty string.

values optional default (none selected)

The value(s) to mark as selected. Pass a single value as plain text, or several values as a JSON array such as ["a","b"] for a multi-value field. Omit it to render every option unselected. A value that is not among the field's options is ignored.

Examples

virtual{fieldoptions:2f3fef5ba522680d1dd5f681a814bf84:switch..........}
Expected
Test (verified)">Actual
Renders one option element per allowed value of the field. The genuine output is HTML markup, so this example is illustrative. Here the select field switch.......... offers two values.
virtual{fieldoptions:2f3fef5ba522680d1dd5f681a814bf84:switch..........:virtual}
Expected
Test (verified)">Actual
The third parameter pre-selects an option. The matching option gains selected class=sel_on; the others stay unselected. Pass the field's current value here when you build an edit form.
test[{fieldoptions:2f3fef5ba522680d1dd5f681a814bf84:headline........}]
Expected[]
Actual[]
A field with no enumerable options - here the plain text field headline.......... - produces an empty string, shown as nothing between the brackets. Only fields with a defined value list (select, checkbox, radio, multiselect, constant group or linked slice) return options.
virtual{fieldoptions:2f3fef5ba522680d1dd5f681a814bf84:switch..........:["test","virtual"]}
Expected
Test (verified)">Actual
For a multi-value field pass the current values as a JSON array; every matching option is marked selected. Use this for multiselect or checkbox fields that hold more than one value.
test[{fieldoptions:2f3fef5ba522680d1dd5f681a814bf84:nope............}]
Expected[]
Actual[]
An unknown field id (or an empty slice_id outside any item context) returns an empty string rather than an error, so the expression is safe to drop into a template even when the field may not exist.