Craft Tips & Tricks
by Alex Van Holtz

1. Content Builders

Using a matrix to create a dynamic content builder. You provide the client with building blocks to create a page. 

Simple Content Builder

Each matrix block represents a single field.

  • [Matrix] Content Builder
  • [Matrix Block] Heading
  • [Plaintext] Heading
  • [Matrix Block] Sub Heading
  • [Plaintext] Sub Heading
  • [Matrix Block] Body
  • [Richtext] Text
  • [Matrix Block] Button
  • [Plaintext] Button Text
  • [Plaintext] Button Link
  • [Asset Selector] Button Download

{% for block in entry.contentBuilder %}
    
    {% switch block.type %}
        {% case 'headline' %}
            <h1 class="center">{{ block.headline }}</h1>
        {% case 'subHeadline' %}
            <h2 class="center">{{ block.subHeadline }}</h2>
        {% case 'text' %}
            <div>
                {{ block.body }}
            </div>
        {% case 'button' %}
            {% set url = block.bDownload.first().url | default(block.bLink) %}
            <div class="center">
                <a href="{{ url }}" target="_blank" class="btn">{{ block.bText }}</a>
            </div>
        {% case 'default' %}            
            {# do nothing if we encounter a block we don't recognize #}
    {% endswitch %}
    
{% endfor %}

Complex Content Builder

Each matrix block represents a grouping of fields.

Example 1 - Copy Block

  • [Matrix] Content Builder
  • [Matrix Block] Copy Block
  • [Plaintext] Heading
  • [Plaintext] Sub Heading
  • [Richtext] Body