0

I have matrix field set up, is that possible to output Name in Field Settings (refer to the handle: aggressiveBehavior)? Thanks

enter image description here

  • That's a crazy long field name! Seems like most of that should go under the "Instructions". – Lindsey D May 24 '17 at 19:18
  • The client wants it to show the question as the title, not the instruction, that's why we put it in the name field. I guess we need a separated field to store it. Thanks – Angela Chan May 26 '17 at 16:55
1

If you must insist on using such a long field name rather than putting it in your twig template, then this code should work:

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

{% for blockType in field.getFieldType.getSettings.blockTypes %}
    {% if blockType == 'pet' %}
        {% for field in blockType.fields %}
            {% if field.handle == 'aggressiveBehavior' %}
                {{ field.name }}
            {% endif %}
        {% endfor %}
    {% endif %}
{% endfor %}
| improve this answer | |
1

I believe that it is not possible looking at the Matrix Block Model Docs.

What I would usually do, instead of having the front end facing title as the Field Name, is keep the Field name solely for the back end.

An example be (for a front end form)

<label>{{ 'Is your pet ever aggressive to strangers?' | t }}</label>
{% for option in matrixBlock.aggressiveBehavior.options %}
<input type="radio" name="aggressiveBehavior" value="{{ option.value }}">{{ option.label }}
{% 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.