1

I know how to get a list of selected checkboxes for a entry:

{% for option in entry.myFieldHandle.options %}
  Label: {{ option.label }}
  Value: {{ option }} or {{ option.value }}
{% endfor %}

But I can't figure out how to simply display a list of available checkboxes of a certain field in the template. This may be needed if I want, for example, to create a form for adding a entry. Is there such a construction?

1 Answer 1

1

If you need to get the options independent of any specific entry, you can use the fields service to get the field and retrieve its options.

{% set field = craft.app.fields.getFieldByHandle('myFieldHandle') %}
{% for option in field.options %}`

In this case, option will be an array with the keys value, label and default (this will be '1' if the option is the default, or an empty string).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.