1

Is there a way in a template to loop through the fields in a field layout without having to tie them to an entry? I'm currently grabbing that list with entry.getFieldLayout(3).getFields(), but that only works when entry is set.

2

This can be done by reaching through the section and entry type to the final field layout. Like this:

{% set section = craft.sections.getSectionByHandle('sectionName') %}
{% set entryType = '' %}
{% for type in section.getEntryTypes %}
    {% if type.handle == 'entryType' %}
        {% set entryType = type %}
    {% endif %}
{% endfor %}
{% set fieldLayout = craft.fields.getLayoutById(entryType.fieldLayoutId) %}

You should be abel to use getFields as normal.

| improve this answer | |
  • Worked like a charm! Thanks. I'm glad I asked. It would have taken me forever (or possibly never) to figure that out on my own. – Philip Jones Feb 22 '16 at 20:10

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.