Learning Craft CMS

Learning

This post is a collection of Craft CMS tags for use in projects. It was handy to use this as a resource while I was learning, & now I mainly use it to make note of more obscure tags / methods that are less well documented.

Singles

{{ entry.fieldName }}

Simple Loop

{% for variableName in craft.entries.section('sectionName') %}
     {{ variableName.fieldName }}
{% endfor %}

Matrix Block (by block type)

{% for variableName in entry.matrixName %}
     {% if variableName.type == "blockName" %}
         {{ variableName.fieldName }}
     {% elseif variableName.type == "blockName" %}
          {{ variableName.fieldName }}
     {% endif %}
{% endfor %}

Conditionals

{% if thing == 'thing' %}
     do this
{% elseif otherThing == variable %}
     do this
{% else %}
     do this
{% endif %}

Check if Entry Exists

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

Get Entry & Filter by Slug

{% for entry in craft.entries.section('sectionName').slug('entrySlug') %}
     CONTENT HERE
{% endfor %}

© 2018

V 4.0