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.
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.
-
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