The Craft Field Cheat Sheetfor

Author Slug Plain Text

Field name

{{ entry.authorSlug }}

"If exists" conditional

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

Body Rich Text

Field name

{{ entry.body }}

"If exists" conditional

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

Custom Meta Matrix

Total number of blocks

{{ entry.customMeta|length }}

Loop through blocks

{% for block in entry.customMeta %}
	...
{% endfor %}

Filtering by block type

{% for block in entry.customMeta.type('text') %}

Adjusting the limit

{% for block in entry.customMeta.limit(5) %}

All block types with fields

{% for block in entry.customMeta %}
	{% switch block.type %}

		{% case="metaText" %}
			{{ block.metaProperty }} {# Type: Plain Text #}
			{{ block.metaContent }} {# Type: Plain Text #}

		{% case="metaImage" %}
			{{ block.metaProperty }} {# Type: Plain Text #}
			{{ block.metaContent }} {# Type: Assets #}

		{% default %}
			...

	{% endswitch %}
{% endfor %}

Custom Title Plain Text

Field name

{{ entry.customTitle }}

"If exists" conditional

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

Full Site Name Plain Text

Field name

{{ entry.fullSiteName }}

"If exists" conditional

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

Image Set Assets

Total number of assets

{{ entry.imageSet|length }}

Common conditional

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

Loop through assets

{% for myAsset in entry.imageSet %}
	{{ myAsset.url }}
{% endfor %}

Only return the first asset

{% set myAsset = entry.imageSet.first() %}
{% if myAsset %}
	{{ myAsset.url }}
{% endif %}

Adjusting the limit

{% for block in entry.imageSet.limit(5) %}

All asset variables

{% set myAsset = entry.imageSet.first() %}
{% if myAsset %}
	{{ myAsset.dateCreated }}
	{{ myAsset.dateUpdated }}
	{{ myAsset.extension }}
	{{ myAsset.filename }}
	{{ myAsset.folder }}
	{{ myAsset.folderId }}
	{{ myAsset.height }}
	{{ myAsset.id }}
	{{ myAsset.img }}
	{{ myAsset.kind }}
	{{ myAsset.locale }}
	{{ myAsset.link }}
	{{ myAsset.mimeType }}
	{{ myAsset.next }}
	{{ myAsset.prev }}
	{{ myAsset.size }}
	{{ myAsset.source }}
	{{ myAsset.sourceId }}
	{{ myAsset.url }}
	{{ myAsset.width }}
{% endif %}

All asset methods

{% set myAsset = entry.imageSet.first() %}
{% if myAsset %}
	{{ myAsset.getExtension() }}
	{{ myAsset.getFolder() }}
	{{ myAsset.getHeight( transform ) }}
	{{ myAsset.getImg() }}
	{{ myAsset.getLink() }}
	{{ myAsset.getMimeType() }}
	{{ myAsset.getNext( params ) }}
	{{ myAsset.getPrev( params ) }}
	{{ myAsset.getSource() }}
	{{ myAsset.getUrl( transform ) }}
	{{ myAsset.getWidth( transform ) }}
	{{ myAsset.setTransform( transform ) }}
{% endif %}

Is New? Lightswitch

Boolean Conditional

{% if entry.isNew %} ... {% endif %}

Journal Intro Rich Text

Field name

{{ entry.journalIntro }}

"If exists" conditional

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

Meta Description Plain Text

Field name

{{ entry.metaDescription }}

"If exists" conditional

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

Opening Image Assets

Total number of assets

{{ entry.openingImage|length }}

Common conditional

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

Loop through assets

{% for myAsset in entry.openingImage %}
	{{ myAsset.url }}
{% endfor %}

Only return the first asset

{% set myAsset = entry.openingImage.first() %}
{% if myAsset %}
	{{ myAsset.url }}
{% endif %}

Adjusting the limit

{% for block in entry.openingImage.limit(5) %}

All asset variables

{% set myAsset = entry.openingImage.first() %}
{% if myAsset %}
	{{ myAsset.dateCreated }}
	{{ myAsset.dateUpdated }}
	{{ myAsset.extension }}
	{{ myAsset.filename }}
	{{ myAsset.folder }}
	{{ myAsset.folderId }}
	{{ myAsset.height }}
	{{ myAsset.id }}
	{{ myAsset.img }}
	{{ myAsset.kind }}
	{{ myAsset.locale }}
	{{ myAsset.link }}
	{{ myAsset.mimeType }}
	{{ myAsset.next }}
	{{ myAsset.prev }}
	{{ myAsset.size }}
	{{ myAsset.source }}
	{{ myAsset.sourceId }}
	{{ myAsset.url }}
	{{ myAsset.width }}
{% endif %}

All asset methods

{% set myAsset = entry.openingImage.first() %}
{% if myAsset %}
	{{ myAsset.getExtension() }}
	{{ myAsset.getFolder() }}
	{{ myAsset.getHeight( transform ) }}
	{{ myAsset.getImg() }}
	{{ myAsset.getLink() }}
	{{ myAsset.getMimeType() }}
	{{ myAsset.getNext( params ) }}
	{{ myAsset.getPrev( params ) }}
	{{ myAsset.getSource() }}
	{{ myAsset.getUrl( transform ) }}
	{{ myAsset.getWidth( transform ) }}
	{{ myAsset.setTransform( transform ) }}
{% endif %}

Price Number

Field name

{{ entry.price }}

Comparison conditional</td>

{% if entry.price > 0 %} ... {% endif %}

Operations

{% set myResult = 42 * entry.price %}

The total is {{ myResult }}

Product Badge Dropdown

Field name

{{ entry.productBadge }}

Field label

{{ entry.productBadge.label }}

Loop through the options

<ul>
	{% for option in entry.productBadge.options %}
		<li>{{ option }}</li>
	{% endfor %}
</ul>

Product Name Plain Text

Field name

{{ entry.productName }}

"If exists" conditional

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

Product Thumb Assets

Total number of assets

{{ entry.productThumb|length }}

Common conditional

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

Loop through assets

{% for myAsset in entry.productThumb %}
	{{ myAsset.url }}
{% endfor %}

Only return the first asset

{% set myAsset = entry.productThumb.first() %}
{% if myAsset %}
	{{ myAsset.url }}
{% endif %}

Adjusting the limit

{% for block in entry.productThumb.limit(5) %}

All asset variables

{% set myAsset = entry.productThumb.first() %}
{% if myAsset %}
	{{ myAsset.dateCreated }}
	{{ myAsset.dateUpdated }}
	{{ myAsset.extension }}
	{{ myAsset.filename }}
	{{ myAsset.folder }}
	{{ myAsset.folderId }}
	{{ myAsset.height }}
	{{ myAsset.id }}
	{{ myAsset.img }}
	{{ myAsset.kind }}
	{{ myAsset.locale }}
	{{ myAsset.link }}
	{{ myAsset.mimeType }}
	{{ myAsset.next }}
	{{ myAsset.prev }}
	{{ myAsset.size }}
	{{ myAsset.source }}
	{{ myAsset.sourceId }}
	{{ myAsset.url }}
	{{ myAsset.width }}
{% endif %}

All asset methods

{% set myAsset = entry.productThumb.first() %}
{% if myAsset %}
	{{ myAsset.getExtension() }}
	{{ myAsset.getFolder() }}
	{{ myAsset.getHeight( transform ) }}
	{{ myAsset.getImg() }}
	{{ myAsset.getLink() }}
	{{ myAsset.getMimeType() }}
	{{ myAsset.getNext( params ) }}
	{{ myAsset.getPrev( params ) }}
	{{ myAsset.getSource() }}
	{{ myAsset.getUrl( transform ) }}
	{{ myAsset.getWidth( transform ) }}
	{{ myAsset.setTransform( transform ) }}
{% endif %}

Related Products Entries

Set your entries to a variable

{% set entries = entry.relatedProducts %}

Does your entries field have any entries?

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

A simple loop for your entries

{% for myEntry in entry.relatedProducts|length %}
	...
{% endfor %}

Set variable, check for entries, then loop through them

{% set entries = entry.relatedProducts %}
{% if entries|length %}
	<h3>List of Entries</h3>
	{% for myEntry in entries %}
		...
	{% endfor %}
{% endif %}

Just grab the first entry

{% set myEntry = entry.relatedProducts.first() %}
{% if myEntry %}
	...
{% endif %}

Rich Body Matrix

Total number of blocks

{{ entry.richBody|length }}

Loop through blocks

{% for block in entry.richBody %}
	...
{% endfor %}

Filtering by block type

{% for block in entry.richBody.type('text') %}

Adjusting the limit

{% for block in entry.richBody.limit(5) %}

All block types with fields

{% for block in entry.richBody %}
	{% switch block.type %}

		{% case="richText" %}
			{{ block.text }} {# Type: Rich Text #}

		{% case="calloutText" %}
			{{ block.calloutText }} {# Type: Plain Text #}
			{{ block.calloutCredit }} {# Type: Plain Text #}

		{% case="productImageLarge" %}
			{{ block.productImageLarge }} {# Type: Entries #}

		{% case="imagesLarge" %}
			{{ block.imagesLarge }} {# Type: Assets #}

		{% case="markdownText" %}
			{{ block.markdownText }} {# Type: Plain Text #}

		{% default %}
			...

	{% endswitch %}
{% endfor %}

Sample Address Smart Map Address

Individual address fields

{{ entry.sampleAddress.street1 }}
{{ entry.sampleAddress.street2 }}
{{ entry.sampleAddress.city }}
{{ entry.sampleAddress.state }}
{{ entry.sampleAddress.zip }}

Latitude: {{ entry.sampleAddress.lat }}
Longitude: {{ entry.sampleAddress.lng }}

{# Only available in proximity search results #}
Found {{ entry.sampleAddress.distance | number_format(1) }} miles away.

Combined address output

{# On 3 lines #}
{{ entry.sampleAddress.format }}

{# On 2 lines #}
{{ entry.sampleAddress.format(true) }}

{# On 1 line #}
{{ entry.sampleAddress.format(true, true) }}

"If address is not empty" conditional

{% if not entry.sampleAddress.isEmpty %} ... {% endif %}

"If address has coordinates" conditional

{% if entry.sampleAddress.hasCoords %} ... {% endif %}

These code examples cover the basic ways to directly output address data. If you'd like to render a map (or do even more complex stuff with your address data), please visit the full documentation at Craft Plus.

Sample Category Categories

Check if entry has categories

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

Rename for easier access

{% set categories = entry.sampleCategory %}
{% if categories|length %}
	<h3>My Categories<h3/>
	{% nav myCategory in categories %}
		...
	{% endnav %}
{% endif %}

Pass parameters to the ElementCriteria Model

{% set myCategories = entry.sampleCategory.order('name') %}

Select just the first category

This is mostly used in a scenario where you only expect one category to be selected. The result is still a "set" of categories so we just grab the "first" one.

{% set myCategory = entry.sampleCategory.first() %}
{% if myCategory %}
	...
{% endif %}

Sample Checkboxes Checkboxes

Field name

{{ entry.sampleCheckboxes }}

Single checkbox conditional

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

Loop through the *selected* options

<ul>
	{% for option in entry.sampleCheckboxes %}
		<li>{{ option }}</li>
	{% endfor %}
</ul>

Loop through <em>all</em> of the options

<ul>
	{% for option in entry.sampleCheckboxes.options %}
		<li>{{ option }}</li>
	{% endfor %}
</ul>

See if a specific option is selected

{% if entry.sampleCheckboxes.contains('value') %}
	...
{% endif %}

Sample Color Color

Field name

{{ entry.sampleColor }}

"If exists" conditional

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

Sample Date/Time Date

Sample date formatting

{% if entry.sampleDateTime %}
	{{ entry.sampleDateTime | date('M j, Y') }}
{% endif %}

Get the Unix timestamp of the date

{{ entry.sampleDateTime.getTimestamp() }}

There are many methods you can use on date fields. More documentation available here.

Sample MultiSelect Multi Select

Loop through the <em>selected</em> options

<ul>
	{% for option in entry.sampleMultiselect %}
		<li>{{ option }}</li>
	{% endfor %}
</ul>

Loop through <em>all</em> of the options

<ul>
	{% for option in entry.sampleMultiselect.options %}
		<li>{{ option }}</li>
	{% endfor %}
</ul>

See if a specific option is selected

{% if entry.sampleMultiselect.contains('value') %}
	...
{% endif %}

Sample Position Select Position Select

Adding to a class name

<div class="block {{ entry.samplePositionSelect }}">

Conditionals around position values

{% if entry.samplePositionSelect in ['left', 'right'] %}
	{# ... #}
{% elseif entry.samplePositionSelect == 'center' %}
	{# ... #}
{% endif %}

Switch statement for all values

{% switch entry.samplePositionSelect %}
	{% case 'left' %}
		{# ... #}
	{% case 'center' %}
		{# ... #}
	{% case 'right' %}
		{# ... #}
	{% case 'full' %}
		{# ... #}
	{% case 'drop-left' %}
		{# ... #}
	{% case 'drop-right' %}
		{# ... #}
{% endswitch %}

Sample Radio Radio Buttons

The Selected value's option

{{ entry.sampleRadio }}

The Selected value's label

{{ entry.sampleRadio.label }}

Loop through all available options

<ul>
	{% for option in entry.sampleRadio.options %}
		<li>{{ option }}</li>
	{% endfor %}
</ul>

Sample Table Table

Table Structure

This the general structure of the table and column handles (and types). If there are any default row values they will are displayed below this structure code block.

{% if entry.sampleTable|length %}
	{% for row in entry.sampleTable %}
		{{ row.name }}      {# singleline #}
		{{ row.age }}       {# number #}
		{{ row.location }}  {# multiline #}
		{{ row.public }}    {# checkbox #}
	{% endfor %}
{% endif %}

Default Values

Row #Name Age Location Public?
125GA1
230FL

Sample Users Users

Set a variable for future template use

{% set myUsers = entry.sampleUsers %}

Check if any users were selected

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

Loop through the selected users

{% for myUser in entry.sampleUsers %}
	...
{% endfor %}

Filter by parameters

{% set authors = entry.sampleUsers.group('groupName') %}

Avoid a loop if your field limits to 1 user

{% set myUser = entry.sampleUsers.first() %}
{% if myUser %}
	...
{% endif %}

Social Profiles Table

Table Structure

This the general structure of the table and column handles (and types). If there are any default row values they will are displayed below this structure code block.

{% if entry.socialProfiles|length %}
	{% for row in entry.socialProfiles %}
		{{ row.twitter }}    {# singleline #}
		{{ row.facebook }}   {# singleline #}
		{{ row.dribbble }}   {# singleline #}
		{{ row.behance }}    {# singleline #}
		{{ row.github }}     {# singleline #}
		{{ row.bitbucket }}  {# singleline #}
		{{ row.instagram }}  {# singleline #}
		{{ row.codepen }}    {# singleline #}
		{{ row.500px }}      {# singleline #}
	{% endfor %}
{% endif %}

Tag Line Plain Text

Field name

{{ entry.tagLine }}

"If exists" conditional

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

Tags Tags

Set a variable for future template use

{% set myTags = entry.tags %}

Check if any tags exist

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

Loop through the selected tags

{% for myTag in entry.tags %}
	...
{% endfor %}

Order by parameters

{% set myTags = entry.tags.order('title') %}

Avoid a loop if your field limits to 1 user

{% if entry.tags.first() %}
	...
{% endif %}