<p>It's a bit awkward to get overwritten labels, since they're not available in the same place as the regular field names – not even on the same object. The regular name is a property of the field object that extends <a href="https://docs.craftcms.com/api/v3/craft-base-field.html" rel="nofollow noreferrer"><code>\craft\base\Field</code></a>, but the overwritten label is only available on a <a href="https://docs.craftcms.com/api/v3/craft-fieldlayoutelements-customfield.html" rel="nofollow noreferrer"><code>craft\fieldlayoutelements\CustomField</code></a> object you can access through the field layout.</p>
<p>Note the difference between those two methods:</p>
<pre class="lang-twig prettyprint-override"><code>{% set fieldLayout = entry.getFieldLayout() %}

{% set customField = fieldLayout.getField('my_custom_field') %}
{% dd customField %}
{# craft\fieldlayoutelements\CustomField #}

{% set field = fieldLayout.getFieldByHandle('my_custom_field') %}
{% dd field %}
{# craft\fields\Categories (or another class extending craft\base\Field) #}
</code></pre>
<p>The overwritten label is available through <code>customField.label</code>, the regular label as <code>field.name</code>. If you're not sure if a field has an overwritten label, you can get it like this and fall back to the regular field name:</p>
<pre class="lang-twig prettyprint-override"><code>{% set fieldLayout = entry.getFieldLayout() %}
{% set customField = fieldLayout.getField('my_custom_field') %}
{% set field = fieldLayout.getFieldByHandle('my_custom_field') %}
{% set label = customField.label|default(field.name) %}
</code></pre>
<p>If there is a simpler method to access the label with a graceful fallback to the field name, I'd be happy to hear it as well!</p>

CC BY-SA 4.0
2021-11-05T14:13:08.737Z
Thanks so much for the quick response, it worked perfectly!
James
CC BY-SA 4.0
2021-11-05T11:47:59.453Z
2021-11-05T11:47:59.453Z
MoritzLost
<p>In a Craft field layout, you can override the label for a field just for that layout/tab. However, when displaying a list of fields on the frontend, I can't find how to get that overridden label, rather than the default for the field.</p>
<p>The code sample below is for a Neo field, but I imagine the same would apply to any field layout. I've tried grabbing the field info from the layout, grabbing the field directly from the fields service, but they both return the original label.</p>
<pre><code>{% set fieldLayoutFields = neoBlock.getFieldLayout().getFields() ??? null %}
{% for fieldLayoutField in fieldLayoutFields %}

    {{ fieldLayoutField.name }}

    {% set field = craft.fields.getFieldById(fieldLayoutField.id) %}

    {{ field.name }}

{% endfor %}
</code></pre>

<field><plugin-neo>
DIsplaying Field Label override on front end
# DIsplaying Field Label override on front end

(Asked by: username_0 on 2021-11-05)

In a Craft field layout, you can override the label for a field just for that layout/tab. However, when displaying a list of fields on the frontend, I can't find how to get that overridden label, rather than the default for the field.
The code sample below is for a Neo field, but I imagine the same would apply to any field layout. I've tried grabbing the field info from the layout, grabbing the field directly from the fields service, but they both return the original label.
{% set fieldLayoutFields = neoBlock.getFieldLayout().getFields() ??? null %}
{% for fieldLayoutField in fieldLayoutFields %}

    {{ fieldLayoutField.name }}

    {% set field = craft.fields.getFieldById(fieldLayoutField.id) %}

    {{ field.name }}

{% endfor %}

**Tags:** field, plugin-neo


---

## 1 answers

### Answer by username_1 on 2021-11-05. Score: 2 | Accepted answer

It's a bit awkward to get overwritten labels, since they're not available in the same place as the regular field names – not even on the same object. The regular name is a property of the field object that extends \craft\base\Field, but the overwritten label is only available on a craft\fieldlayoutelements\CustomField object you can access through the field layout.
Note the difference between those two methods:
{% set fieldLayout = entry.getFieldLayout() %}

{% set customField = fieldLayout.getField('my_custom_field') %}
{% dd customField %}
{# craft\fieldlayoutelements\CustomField #}

{% set field = fieldLayout.getFieldByHandle('my_custom_field') %}
{% dd field %}
{# craft\fields\Categories (or another class extending craft\base\Field) #}

The overwritten label is available through customField.label, the regular label as field.name. If you're not sure if a field has an overwritten label, you can get it like this and fall back to the regular field name:
{% set fieldLayout = entry.getFieldLayout() %}
{% set customField = fieldLayout.getField('my_custom_field') %}
{% set field = fieldLayout.getFieldByHandle('my_custom_field') %}
{% set label = customField.label|default(field.name) %}

If there is a simpler method to access the label with a graceful fallback to the field name, I'd be happy to hear it as well!

> **Comments:**
> **username_0**: Thanks so much for the quick response, it worked perfectly!  

---

