<p>You'll need to use the Fields service (this changed in Craft 3):</p>
<pre><code>{% set body = craft.app.fields.getFieldByHandle('body') %}
</code></pre>
<p>For more info see <a href="https://craftcms.com/docs/4.x/dev/global-variables.html#common-services" rel="nofollow noreferrer">Common Services</a> in the docs.</p>

CC BY-SA 4.0
2022-11-18T18:14:52.197Z
Thank you! I realised this at the exact same time you posted your answer of course! I'll accept your answer with thanks however.
Tchick
CC BY-SA 4.0
2022-11-18T18:12:27.263Z
2022-11-18T18:12:27.263Z
CraftQuest
<p>I see craft.fields.getFieldByHandle() is deprecated and replaced with craft.app.fields.getFieldByHandle()</p>
<p>See: <a href="https://craftcms.stackexchange.com/a/35811/4060">https://craftcms.stackexchange.com/a/35811/4060</a></p>

CC BY-SA 4.0
2022-11-18T18:12:54.800Z
2022-11-18T18:12:54.800Z
Tchick
<p>In Craft 2, I used to be able to do this:
<a href="https://craftcms.com/docs/2.x/templating/craft.fields.html#getfieldbyhandle-handle" rel="nofollow noreferrer">https://craftcms.com/docs/2.x/templating/craft.fields.html#getfieldbyhandle-handle</a></p>
<pre><code>{% set body = craft.fields.getFieldByHandle('body') %}
{{ body.instructions }}
</code></pre>
<p>In Craft 4 this no longer works - is there an updated syntax?
I need to be able to get the field name when I only have its handle.</p>

<templating><craft4>
Craft 4: How do I get field by handle?
# Craft 4: How do I get field by handle?

(Asked by: username_0 on 2022-11-18)

In Craft 2, I used to be able to do this:
https://craftcms.com/docs/2.x/templating/craft.fields.html#getfieldbyhandle-handle
{% set body = craft.fields.getFieldByHandle('body') %}
{{ body.instructions }}

In Craft 4 this no longer works - is there an updated syntax?
I need to be able to get the field name when I only have its handle.

**Tags:** templating, craft4


---

## 2 answers

### Answer by username_1 on 2022-11-18. Score: 2 | Accepted answer

You'll need to use the Fields service (this changed in Craft 3):
{% set body = craft.app.fields.getFieldByHandle('body') %}

For more info see Common Services in the docs.

> **Comments:**
> **username_0**: Thank you! I realised this at the exact same time you posted your answer of course! I'll accept your answer with thanks however.  

---

### Answer by username_0 on 2022-11-18. Score: 1

I see craft.fields.getFieldByHandle() is deprecated and replaced with craft.app.fields.getFieldByHandle()

See: <https://craftcms.stackexchange.com/a/35811/4060>


---

