<p>With Craft 4, you may need to be a little more specific about what you intend to get. The field layout itself can include field layout elements, which can include UI niceties that are <em>not</em> custom fields that take content. It can also include <em>native</em> fields (like <em>Title</em>) and <em>custom</em> fields you’ve added.</p>
<p>Check out the methods on the <a href="https://docs.craftcms.com/api/v4/craft-models-fieldlayout.html" rel="nofollow noreferrer">FieldLayout model</a>. To approximate your Craft 3 example, you could use <code>getCustomFields()</code> instead of <code>getFields()</code> to list the <em>custom</em> fields for the entry:</p>
<pre><code>{% for field in entry.getFieldLayout().getCustomFields() %}
  {{ field.handle }} : {{ entry[field.handle] }}
{% endfor %}
</code></pre>
<p>You could list <em>all</em> of the field handles, as they appear in the field layout tabs, like this:</p>
<pre><code>{% for tab in entry.getFieldLayout().getTabs() %}
  {# output tab.name here if you want #}
  {% for element in tab.getElements() %}
    {{ element.attribute }} : {{ entry[element.attribute] }}
  {% endfor %}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2022-09-28T21:59:39.490Z
2022-09-28T21:59:39.490Z
Matt Stein
<p>How to display all fields belonging to current entry in Craft 4? There is an answer to the similar question for Craft 3, but it does not work for Craft 4:</p>
<pre><code>{# loop through the fields in the entries fieldLayout Model #}
{% for fieldLayoutField in entry.getFieldLayout().getFields() %}

    {# get the field Model from the fieldId #}
    {% set field = craft.fields.getFieldById(fieldLayoutField.fieldId) %}

    {# print the field handle and the field content  #}
    {{ field.handle }} : {{ entry.getContent()[field.handle] }}

{% endfor %}
</code></pre>
<p>I tried to find corresponding methods at the docs, but it seems the versions differ too much.</p>

<entry>
How to display all fields belonging to current entry in Craft 4?
# How to display all fields belonging to current entry in Craft 4?

(Asked by: username_0 on 2022-09-28)

How to display all fields belonging to current entry in Craft 4? There is an answer to the similar question for Craft 3, but it does not work for Craft 4:
{# loop through the fields in the entries fieldLayout Model #}
{% for fieldLayoutField in entry.getFieldLayout().getFields() %}

    {# get the field Model from the fieldId #}
    {% set field = craft.fields.getFieldById(fieldLayoutField.fieldId) %}

    {# print the field handle and the field content  #}
    {{ field.handle }} : {{ entry.getContent()[field.handle] }}

{% endfor %}

I tried to find corresponding methods at the docs, but it seems the versions differ too much.

**Tags:** entry


---

## 1 answers

### Answer by username_1 on 2022-09-28. Score: 3 | Accepted answer

With Craft 4, you may need to be a little more specific about what you intend to get. The field layout itself can include field layout elements, which can include UI niceties that are not custom fields that take content. It can also include native fields (like Title) and custom fields you’ve added.
Check out the methods on the FieldLayout model. To approximate your Craft 3 example, you could use getCustomFields() instead of getFields() to list the custom fields for the entry:
{% for field in entry.getFieldLayout().getCustomFields() %}
  {{ field.handle }} : {{ entry[field.handle] }}
{% endfor %}

You could list all of the field handles, as they appear in the field layout tabs, like this:
{% for tab in entry.getFieldLayout().getTabs() %}
  {# output tab.name here if you want #}
  {% for element in tab.getElements() %}
    {{ element.attribute }} : {{ entry[element.attribute] }}
  {% endfor %}
{% endfor %}


---

