Craft CMS Field Guide

Example Twig code for all default Craft CMS field types.

The output tags below are only examples to help get you started. There are many additional ways you can output and manage your data in templates.

General Fields

Single-Tag Loop Conditional
Plain Text
{{ entry.plainTextField }}
Rich Text
{{ entry.richTextField }}
Color
{{ entry.colorField }}
Number
{{ entry.numberField }}
Date
{{ entry.dateField|date('M j, Y') }}
Lightswitch
{{ user.lightswitchField }}

Single Choice Fields

Single-Tag Loop Conditional
Dropdown
{{ entry.dropdownField }}
{% for option in entry.dropdownField.options %}
    {{ option }}
{% endfor %}
{% if option.selected %}
    ...
{% endif %}
Radio Buttons
{{ entry.radioField }}
{% for option in entry.radioField.options %}
    {{ option }}
{% endfor %}
{% if option.selected %}
    ...
{% endif %}
Position Select
{{ entry.positionSelectFieldHandle }}
        
{% switch entry.positionSelectFieldHandle %}
{% case 'left' %}
    ...
{% case 'right' %}
    ...
{% case 'center' %}
    ...
{% endswitch %}
          
        

Multiple Choice Fields

Single-Tag Loop Conditional
Checkboxes
{% for option in entry.checkboxField %}
    {{ option }}
{% endfor %}

{% for option in entry.checkboxField.options %}
    {{ option }}
{% endfor %}
{% if option.selected %}
    ...
{% endif %}
Muti-select
{% for option in entry.multiselectField %}
    {{ option }}
{% endfor %}

{% for option in entry.multiselectField.options %}
    {{ option }}
{% endfor %}
{% if option.selected %}
    ...
{% endif %}

Relations

Single-Tag Loop Conditional
Assets
{% for asset in entry.assetsField %}
    {{ asset.url }}
{% endfor %}
{% if entry.assetsField|length %}
    ...
{% endif %}
Categories (Single-Level)
{% for category in entry.categoriesField %}
    {{ entry.title }}
{% endfor %}
{% if entry.categoriesField|length %}
    ...
{% endif %}
Entries
{% for entry in entry.entriesField %}
    {{ entry.title }}
{% endfor %}
{% if entry.entriesField|length %}
    ...
{% endif %}
Tags
{% for tag in entry.tagsField %}
    {{ tag.name }}
{% endfor %}
{% if entry.tagsField|length %}
    ...
{% endif %}
Users
{% for user in entry.usersField %}
    {{ user.firstName }} {{ user.lastName }}
{% endfor %}
{% if entry.usersField|length %}
    ...
{% endif %}

Structured Relations

Single-Tag Loop Conditional
Categories (Multi-Level)
<ul>
                {% nav category in entry.categoriesField %}
                <li>
    {{ category.title }}

    {% ifchildren %}
                <ul>
                {% children %}
                </ul>
                {% endifchildren %}
                </li>
                {% endnav %}
                </ul>

{% if entry.categoriesField|length %}
    ...
{% endif %}
Entries (Structures)
<ul>
                {% nav entry in entry.entriesField %}
                <li>
    {{ entry.title }}

    {% ifchildren %}
                <ul>
                {% children %}
                </ul>
                {% endifchildren %}
                </li>
                {% endnav %}
                </ul>
{% if entry.entriesField|length %}
    ...
{% endif %}

Rows and Columns

Single-Tag Loop Conditional
Table
<table>
                {% for row in entry.tableField %}
                <tr>
                <td>{{ row.fieldOne }}</td>
                <td>{{ row.fieldTwo }}</td>
                </tr>
                {% endfor %}
                </table>
{% if entry.tableField|length %}
    ...
{% endif %}
Matrix
{% for block in entry.matrixField %}
    ...
{% endfor %}

{% if entry.matrixField|length %}
    ...
{% endif %}

{% if block.type == "heading" %}
                <h3>{{ block.heading }}</h3>
                {% else %}
    {{ block.body }}
{% endif %}

Level up in Craft CMS with practical examples, snippets, and patterns.
Craft The Planet emails are sent out several times a week.