1

I can get a list of option labels available in a dropdown field using the code below. Is there a way to get a list of option labels that have been assigned to entries in a specific section?

{% for cocktailTypes in craft.fields.getFieldByHandle('cocktails').getFieldType.options %}
    <p>{{ cocktailTypes.label }}</p>
{% endfor %}
1

I think you need to loop all entries of that sections to "collect" them.

{% set cocktailTypes = [] %}
{% for entry in craft.entries.section('mySection') %}
    {% set cocktailTypes = cocktailTypes|merge([entry.cocktails]) %}
{% endfor %}

{% for cocktailType in cocktailTypes|sort %}
    <p>{{ cocktailType }}</p>
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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