Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Latest commit

 

History

History
56 lines (41 loc) · 1010 Bytes

README.md

File metadata and controls

56 lines (41 loc) · 1010 Bytes

Statamic-Field-Options

Get a field's options from a fieldset.

Useful for grabbing options from a select fieldtype.

Usage

If your field has key/value options, like the following:

colors:
  type: select
  options:
    f00: Red
    0f0: Green
    00f: Blue

Then you can use {{ key }} and {{ value }} respectively:

<select>
{{ field_options field="colors" }}
  <option value="{{ key }}">{{ value }}</option>
{{ /field_options }}
</select>

But if you have unnamed keys, like so:

colors:
  type: select
  options:
    - Red
    - Green
    - Blue

{{ value }} will be all you need. (Since key here would just be indexes)

<select>
{{ field_options field="colors" }}
  <option value="{{ value }}">{{ value }}</option>
{{ /field_options }}
</select>

Parameters

  • fieldset: If your page doesn't have a _fieldset defined in the front-matter, you can specify your fieldset manually here.
  • field: The name of the field you want to grab options from.