CraftQuest Articles

Tutorials, tips, and thoughts on Craft CMS, modern web development, and more.

Image

What is a Field Type in Craft CMS?

Posted on May 11, 2021 by Ryan Irelan

Reading time: 48 seconds

A Craft CMS field type is a type of HTML field you use to cre­ate Pub­lish Lay­outs for your Craft CMS project and store data asso­ci­at­ed with Elements.

A field type is not just an HTML ele­ment, like an input field, textarea, or select. Field types in Craft can be any of the HTML ele­ments, but what makes a Craft CMS field type is the HTML ele­ment it uses plus the func­tion­al­i­ty it pro­vides. The field type you choose will deter­mine the UI and the kind of data that it can store.

As an exam­ple, the HTML ele­ment select is a way to select one item from a list of many via a sim­ple touch­able or click­able interface.

The in-built ver­sion of this in Craft is the Drop­down Field. It func­tions just like a select ele­ment, but Craft gives you the abil­i­ty to cre­ate a new instance of the Drop­down field and set the options via a set­ting UI in the Craft con­trol panel. 

Dropdown of all field types in Craft CMS

You can then use the Drop­down Field in a Craft pub­lish lay­out to col­lect infor­ma­tion for a Craft ele­ment, like an Entry, Cat­e­go­ry, or Asset. 

Addi­tion­al­ly, when you want to query for an ele­ment that has the Drop­down field you cre­at­ed and dis­play it in a Twig tem­plate, Craft pro­vides ways to access the data stored by that instance of the field.

Craft comes with 19 field types built-in for you to use in a project. All of the stan­dard options are avail­able, like text input, drop­down field, mul­ti-select, and cat­e­gories. There are also some Craft-spe­cif­ic field types like Matrix, Cat­e­gories, and Assets. These fields use basic HTML field ele­ments but com­bine them and add addi­tion­al functionality.

If you want a field type beyond what is avail­able in Craft CMS, you can choose one from those avail­able in the Craft Plu­g­in Store or cre­ate your own Craft CMS field type.

© 2021 Mijingo, LLC