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

<pre><code>{% 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) %}
</code></pre>

<p>You should be abel to use <code>getFields</code> as normal.</p>

CC BY-SA 3.0
2016-02-22T20:10:24.227Z
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
CC BY-SA 3.0
2016-02-22T19:58:42.813Z
2016-02-22T19:58:42.813Z
Bryan Redeagle
<p>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 <code>entry.getFieldLayout(3).getFields()</code>, but that only works when <code>entry</code> is set.</p>

<templating><field><loop>
Loop through fields in field layout when `entry` is not set
# Loop through fields in field layout when `entry` is not set

(Asked by: username_0 on 2016-02-22)

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.

**Tags:** templating, field, loop

---

## 1 answers

### Answer by username_1 on 2016-02-22. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_0**: 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.  

---

