<p>There might be other ways, but here's one possibility:</p>
<pre><code>{{ craft.app.fields.getFieldByHandle('yourFieldHandle').className() }}
</code></pre>
<p>This will return a string of <code>craft\fields\PlainText</code>, <code>craft\fields\Lightswitch</code> etc, which you can then use in conditionals/switch statements.</p>

CC BY-SA 4.0
2020-06-22T19:12:57.157Z
Thank you, that worked! But why is it suddenly that complicated?
Marcus Scheller
CC BY-SA 4.0
2020-06-23T10:20:28.223Z
A question I ask myself almost daily... not so much in relation to Craft, but the whole web dev industry. I'm not best placed to answer it in relation to Craft, but I would hazard a guess that these kind of changes relate to the fact that Craft 3 is far more sophisticated than Craft 2: the added sophistication means technical debt needs to be very tightly managed, and limiting a field's output to be a simple string instead of a complex object with actionable methods like `getField()` is probably a significant performance boost. Just guessing, who knows...
James Smith
CC BY-SA 4.0
2024-05-02T20:24:25.290Z
Thanks James. I was jumping through all sort of hoops with field.hasProperty() before finding this. Much simpler than what I was doing :)
Jonathan Schofield
CC BY-SA 4.0
2020-06-22T14:02:22.510Z
2020-06-22T14:02:22.510Z
James Smith
<p>I need to get the field type in my templates like I used to do: <code>field.getField.type</code> but that does not seem to be working in Craft 3 anymore. The result is always <code>null</code>. It also seems that the »type« column is gone completely from the craft_fields table.</p>
<p>How do I get the field type in Craft 3?</p>

<templating><craft3><field>
Get field type in templates
# Get field type in templates

(Asked by: username_0 on 2020-06-22)

I need to get the field type in my templates like I used to do: `field.getField.type` but that does not seem to be working in Craft 3 anymore. The result is always `null`. It also seems that the »type« column is gone completely from the craft\_fields table.

How do I get the field type in Craft 3?

**Tags:** templating, craft3, field


---

## 1 answers

### Answer by username_1 on 2020-06-22. Score: 4 | Accepted answer

There might be other ways, but here's one possibility:
{{ craft.app.fields.getFieldByHandle('yourFieldHandle').className() }}

This will return a string of craft\fields\PlainText, craft\fields\Lightswitch etc, which you can then use in conditionals/switch statements.

> **Comments:**
> **username_0**: Thank you, that worked! But why is it suddenly that complicated?  
> **username_1**: A question I ask myself almost daily... not so much in relation to Craft, but the whole web dev industry. I'm not best placed to answer it in relation to Craft, but I would hazard a guess that these kind of changes relate to the fact that Craft 3 is far more sophisticated than Craft 2: the added sophistication means technical debt needs to be very tightly managed, and limiting a field's output to be a simple string instead of a complex object with actionable methods like `getField()` is probably a significant performance boost. Just guessing, who knows...  
> **username_2**: Thanks James. I was jumping through all sort of hoops with field.hasProperty() before finding this. Much simpler than what I was doing :)  

---

