3

I'm asking this outside an entry context.

My starting point is

{% set field = craft.app.fields.getFieldByHandle('matrixFieldHandle') %}

When I print the data of the field, I find nothing related to the fields that matrixFieldHandle contains.

  • matrixFieldHandle (Matrix field)
    • Block Log
      • Field logValue (Dropdown field)

I know how to print the options in a dropdown field:

But how can I print all these dropdown options when it is set inside a Matrix?

  • What happens if you loop through field and print field.log? – Urs Sep 6 '18 at 15:02
  • I get a Twig Runtime Error: Calling unknown method. – Romain Poirier Sep 6 '18 at 15:06
1

This can be done like so...

{% set matrix = craft.app.fields.getFieldByHandle('myMatrixField') %}
{% for field in matrix.blockTypeFields if field.handle=='myDropdownField'  %}
    <select>
    {% for option in field.options %}
        <option value="{{ option.value }}">{{ option.label }}</option>
    {% endfor %}
    </select>
{% endfor %}
|improve this answer|||||

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.