We use cookies to make your viewing experience better. By accepting you consent, you agree to our Cookie policy

Accept
Improve your Craft CMS skills

Craft CMS: Matrix Fields And Blocks

10 min read
Shape April 2022 HR 28

Struggling to create flexible, modular content in Craft CMS? Matrix fields provide the solution. By combining repeatable blocks of fields, matrices enable creating adaptable multi-section pages, reusable modules, and structured data beyond rigid traditional fields. This guide will explore the power of matrix building blocks, from dynamic configuration to streamlining complex entries and modeling nested data. Discover how to maximize Craft’s matrices for agile, future-proof content.

Matrix fields in Craft CMS enable flexible content modeling using blocks of fields. Blocks can be dynamically added, reordered, and contain various field types. Matrices allow modular, reusable content structures for multi-section pages, forms, and complex data relationships. When traditional fixed fields are too limiting, matrices provide versatile structured content authoring.

What are Matrix Fields in Craft CMS?

Definition and Explanation of Matrix Fields

Matrix fields in Craft CMS enable you to create flexible content structures made up of blocks, rows and subfields. Unlike regular fields that store a single value like a text string or number, matrix fields contain multiple blocks which can hold unlimited types of content and be reordered or deleted.

Each matrix field is made up of blocks which represent rows of content. Within each block you can have multiple columns or subfields like text boxes, dropdowns, images etc to capture different content types. This modular "field within a field" structure makes matrix fields perfect forflexible content modules, multi-step forms and nested or repeatable data.

A key difference versus regular Craft fields is that matrix fields let site editors dynamically create, manage and output multiple "repeating" content blocks within a single field. The content model is no longer rigid or linear. Matrix fields adapt based on the number, order and type of blocks added. This brings huge flexibility for both site development and content creation.

In summary, matrix fields are a field type in Craft CMS that enable you to create flexible content structures made of repeatable blocks containing multiple subfields. Their modular nature provides versatility when building editable content modules and capturing complex or nested data structures.

Matrix Field Settings and Configuration

When creating a new matrix field in Craft there are several configuration settings available to control the structure and editing experience:

  • Minimum Blocks - The minimum number of blocks that must be created for this field. This ensures content editors add the required blocks.

  • Maximum Blocks - The maximum number of blocks allowed for this field. Useful for limiting blocks if needed.

  • Field Layout - Defines the editable fields within each block. Here you can add any number of subfields like text boxes, images, tables etc.

  • Manage Blocks - Controls how blocks can be managed. Options include adding, deleting, collapsing, disabling and reordering blocks.

  • Block Types - Allows creation of multiple different block types with custom field layouts. Content editors can choose the needed block type when editing.

  • Display Settings - Configures how matrix content will be rendered on the front-end like HTML wrappers and separator characters.

These settings allow developers to customise the matrix field structure for the content model needed. For example requiring at least 2 blocks, limiting to 4 blocks maximum or setting a specific field layout per block.

Examples of Common Matrix Field Settings

Some common examples of matrix field configuration for different goals are:

  • SEO Optimised - Add blocks for H2, H3, paragraphs etc. Limit to 1 H2 to avoid multiple H1s. Allow reordering for optimised content structure.

  • Structured Data - Create block schema for key data entities needed. Define required blocks and fields to ensure completeness. Use field naming for schema properties.

  • Flexible Content - Allow unlimited blocks with sidebar and embed subfields. Enable adding, deleting, reordering blocks on the fly. Provide wrapper divs for styling flexibility.

  • Multi-Step Form - Create a block per form step. Set minimum and maximum blocks to match number of steps. Lock block order and types. Display step numbers.

  • Repeatable Data - Allow unlimited blocks with subfields for attributes like title and description. Let editors create as many blocks as needed. Use field naming for database schema.

In summary, matrix settings can be tuned to the specific editorial and technical goals needed, whether optimising for SEO, implementing structured data, enabling flexible content or capturing repeating data. The ability to customise the matrix field structure is key to their versatility in Craft CMS.

Using Matrix Blocks in Craft CMS

What are Matrix Blocks?

Matrix blocks are the fundamental modular content units that make up a matrix field in Craft CMS.

Within a matrix field, blocks represent rows of content that editors can add dynamically. Each block functions like a container that can hold multiple subfields like text, images, tables etc. By adding and organising these content blocks, editors can build up complex flexible content structures.

The key difference versus regular fields is that multiple blocks can be created, managed and output within a single matrix field. This provides the modular flexibility that sets matrix fields apart in Craft CMS. The field adapts to the number and type of blocks added rather than having a fixed rigid structure.

In summary, matrix blocks are modular content units that enable flexible editable structures to be created via repeatable rows that support multiple subfields. They are the fundamental building blocks that empower matrix fields in Craft CMS.

Adding, Organizing and Managing Matrix Blocks

When editing a matrix field in the Craft control panel, adding and managing blocks is easy and intuitive.

To add a new block, simply click the "New block" button and choose the desired block type if multiple exist. The new block will be added to the end by default. You can then fill out the block's subfields like text boxes, images etc to populate it with content.

Blocks can be reordered by clicking and dragging the block handle icon on the left. Dropping a block between two other blocks will insert it at that position. Blocks can also be duplicated via the block settings menu.

The block settings menu accessed via the cog icon also lets you collapse, disable or delete individual blocks. Any disabled or collapsed blocks will not be output on the front-end but can be edited later if needed.

Overall, adding, reordering and managing matrix blocks is very straightforward directly within the Craft CMS control panel interface. The drag and drop functionality makes organizing modular content simple and intuitive.


Types of Matrix Blocks

There are many different block types that can be created within a matrix field in Craft CMS:

Text Blocks - These contain one or more text field subfields for entering plaintext content like paragraphs, headings etc. Settings control formatting and structure.

Image Blocks - These contain an image field for uploading and cropping photos along with other metadata fields. Great for image galleries.

Table Blocks - These allow capturing structured data in a table format with customised columns and rows. Useful for schedules, pricing etc.

Grid Blocks - These contain multiple subfields laid out in uniform columns and rows creating a grid structure. Perfect for staff directories etc.

Embed Blocks - These provide an embed or iframe field to allow embedding videos, maps, social posts etc from external services.

Custom Blocks - Developer-defined block types can have any combination of field layouts needed for the content model.

In summary, matrix fields support nearly all standard Craft CMS field types within their blocks like text, images, tags, categories, tables etc. The ability to create custom block types also provides limitless content modelling flexibility. Matrix blocks enable modular content structures tailored to any editorial requirements.

Benefits of Using Matrix Fields

Flexibility and Modular Content

One of the biggest benefits of matrix fields is the flexibility and modular approach they provide for content creation.

The ability to build content models using repeatable blocks containing multiple subfields makes matrix fields extremely adaptable. Content can be dynamically shaped based on the number and type of blocks added.

This modular architecture is perfect for flexible content modules like accordions, tabs, FAQs, pricing tables etc where the number of items is variable. Matrix fields allow creating these modules without rigidly predefined content structures.

Matrix work great for multi-section pages like services or case studies by using a block per section. Blocks can be reordered, added and removed to fit the content needed. Layouts adapt seamlessly as blocks change.

In summary, the block-based modular architecture of matrix fields enables highly flexible and agile content modelling not easily achievable with traditional fixed fields.

Reusable Matrix Blocks

Another benefit of matrix fields is the ability to create reusable blocks that can streamline content creation.

For example, a "Testimonial" block can be reused across any entries that display testimonials like case studies, services and about us pages. Updating the shared block automatically updates all entries using it.

Shared matrix blocks work great in global content models. A reusable "Office Location" block can power the locations section across regional landing pages by dropping it into the needed entries.

At the section level, a reusable "Content Section" matrix block with subfields for title, body and image can standardize section creation for flexible page layouts.

In summary, crafting reusable matrix blocks is an extremely powerful way to standardize and simplify multi-channel content creation.

Streamlined Editing for Complex Entries

Matrix fields create a streamlined authoring environment for complex entry models that can be cumbersome with traditional fixed fields.

For example, multi-section pages often require scrolling through long forms to edit all fields. With matrices, sections become self-contained blocks that can be edited independently.

Relationships between complex field data like images and alt text are clearer when contained within a matrix block rather than spread across an expansive entry form.

Matrix blocks also enable segmenting long forms into logical steps. Multi-page forms can have a block per step guiding users incrementally through the content model.

In summary, matrix fields allow you to create streamlined and structured content models for complex entries like multi-page or multi-section websites, nested data structures and multi-step forms.

Setting up a Matrix Field in Craft CMS

Step-by-Step Guide to Matrix Creation

Creating a new matrix field in Craft CMS is straightforward using the following step-by-step process:

  1. Navigate to Settings → Fields and click the "New field" button.

  2. Select "Matrix" as the field type and give it a useful name like "Page Sections".

  3. Choose the section and field layout where the matrix should be available. This defines which content editors can access it.

  4. Configure the minimum and maximum blocks allowed. For flexible sections, set high limits or leave unlimited.

  5. Define the field layout for each block. Click "New block type" and add subfields like Text, Images etc.

  6. Set user permissions determining who can manage blocks within the matrix. Allow admins full control.

  7. Enable needed block management settings like adding, duplicating, disabling and deleting blocks.

  8. Optionally enable additional features like enforcing block order or enabling custom block styling.

  9. Click "Save" to create the matrix field. It will now be available to selected sections and editors.

  10. When creating entries, users will see the new matrix field allowing them to add, edit and manage blocks dynamically.

Following these steps enables quickly setting up a tailored matrix field with just a few configuration options for getting started. More advanced settings can be applied later if needed.

Configuring Matrix Field Settings

Some key settings when initially configuring a matrix field include:

  • Block Management - Controls how blocks can be manipulated by enabling adding, duplicating, disabling and deleting blocks.

  • Field Layout - Defines the subfields within each block like Text, Dropdowns, Images etc. Add as many needed.

  • Min/Max Blocks - Sets the minimum and maximum number of blocks allowed. Can prevent empty matrices or limit block creation.

  • Block Order - Enables manually ordering blocks or auto-order alphabetically or by creation date.

  • Content Table - Shows a table on the edit page listing all blocks in a handy overview.

Taking time to properly configure these settings upfront ensures the matrix provides the desired authoring experience for content editors and structure needed for rendering on the frontend.

Adding Blocks and Matrix Fields

When first creating a matrix, it's important to add at least one initial block with subfields that match the content model needed.

For example, a "Text Section" block would have subfields like a Text field for body content, a Text field for the title, and an Assets field for the section image. This defines the schema.

Additional blocks can be added right away or later by editors. You can also create multiple block types with different field layouts and enable adding all needed types dynamically.

Fields within blocks can contain most standard Craft field types like Text, Images, Categories, etc. This allows capturing very complex data structures within matrices in a streamlined way.

In summary, defining reusable blocks with appropriate subfields and enabling needed block types upfront sets up the matrix for success by matching the content model required.

Key Use Cases for Matrix Fields

Multi-Section Pages

One of the most common use cases for matrix fields is powering multi-section pages like services, team bios, product pages etc

For example, each section of a services page can be its own matrix block. This keeps content for each service modular and separate. Services can be reordered, added or removed by simply managing the blocks.

Similarly, team bio pages work great as a matrix with a block for each team member. Reordering or adding new members is easy. And each block can have custom fields like name, bio, headshot etc tailored to capturing employee data.

Product pages also thrive as matrices. Product details live in their own block, as do related content like specs, tutorials, FAQs etc. Custom blocks like "Reviews" provide flexibility to enhance product pages over time.

In summary, matrix fields shine for multi-section pages where content is modular yet needs to dynamically adapt based on the number and order of sections required.

Modular Content Blocks

Sliders, galleries, hero sections, widgets, promotional blocks and other "modular" content elements are also perfect for matrix fields given their reusable and repeatable nature.

For example, a Hero Section matrix block makes it simple to create consistently structured hero sections across a site. The block defines the content model for hero copy, images, buttons etc while enabling creating unlimited heros.

A Reviews or Testimonials matrix block can provide a reusable widget or module for adding user reviews anywhere reviews are needed. The modular design ensures a consistent display while enabling easily adding more reviews over time.

In summary, crafting reusable matrix blocks for modular content elements simplifies creating consistent yet dynamic page elements.

Structured Data Content

Matrix fields are also invaluable for managing structured data content like recipes, products, charts, tables, events or other datasets.

For example, a recipe matrix can include per-recipe blocks with fields for ingredients, instructions, cook time, etc that capture recipe data in a structured way. The matrix maps directly to recipe schema.

Product comparison pages benefit from matrices. Product blocks include pricing, features, ratings etc. Products are output in a table with block fields populating columns. Matrices directly model comparison data.

In summary, matrix fields provide an intuitive way for content editors to create structured data content that also makes display and integration easy for developers. The blocks elegantly map to common data schemas.

Best Practices for Matrix Fields

Organizing Matrix Blocks

When working with matrix fields, following some key tips for thoughtfully organizing blocks helps create cohesively structured content that is easy to manage over time. Rather than haphazardly arranging blocks, aim for purposeful organization strategies like grouping similar blocks together - for example keeping all text section blocks together rather than mixing with other block types.

Maintaining a consistent order for certain blocks, such as always putting topic intro blocks before detailed topic blocks, also brings uniformity. Chronological ordering works well for sequential content like timelines or event listings. Placing reusable blocks used across entries, like testimonials, at the end of the matrix allows them to be more easily portable to other entries.

Disabled or collapsed blocks are handy for temporarily hiding blocks from output without losing their order. While auto-sort options have their place, thoughtfully manual block reordering based on a methodical grouping and sequence ultimately allows for the most refined content structure.

For very long matrices, dividing blocks into multiple matrix fields can provide more manageable chunking. Overall, following purposeful block organization practices makes entries more findable and usable for editors while also improving consistency on the frontend output.

Optimizing Matrix Field Settings

When initially setting up matrix fields, taking time to optimize the configurations for the content editors who will use them is key for creating an effective and efficient authoring experience.

Rather than arbitrarily setting limits, establish logical minimums and maximums on blocks to prevent unusable sparse or overly dense matrices while still allowing flexibility.

Clear and consistent naming conventions for the matrix itself and the nested fields based on their content model roles aids editor understanding. Only enable the actual block types needed by users rather than including every possible option by default to prevent choice paralysis.

Validating field settings like required fields helps ensure accuracy for critical blocks. Introductory instructional text explaining how the matrix should be used provides helpful guidance. Enabling Preview Mode allows testing content formatting during entry creation.

Taking time upfront to optimize the matrix interface and settings through strategies like these pays dividends for editors via more easily and accurately completed matrices requiring less oversight.

Planning Matrix Content for Editors

When initially rolling out matrix fields to content teams, some best practices include providing supplemental resources and training to set them up for success. Documentation like help guides or video tutorials are useful for explaining how to effectively leverage matrices.

Training content creators on core matrix concepts ensures they understand the approach of modular blocks containing nested fields. Establishing governance with guidelines like required blocks or standardized sequencing for specific blocks brings continuity.

Reusable blocks for common repeating elements like testimonials or location information enable consistency. Setting up notifications or reviews may be warranted if higher oversight is needed to enforce matrix compliance, especially initially.

Soliciting editor feedback identifies pain points in real-world use that can inform iterative refinements.

Investing in training, documentation and governance maximizes the value of matrices by empowering editors to efficiently build cohesive, structured content at scale.

Comparing Matrix Fields to Other Field Types

Matrix vs Table Fields

Matrix and Table fields in Craft both allow capturing structured data, but with different approaches:

Matrices are optimized for flexible content modeling using blocks of fields. Table fields capture tabular data in simple rows and columns.

Matrices shine where modular or repeating content blocks are needed, like accordions or product pages with tabs. Tables excel at simple datasets like schedules, charts or pricing tables.

Matrix blocks can contain unlimited types of fields like text, images, tables etc. Table rows are limited to predefined cell fields.

Matrix blocks can be added, deleted, reordered dynamically. Table rows are fixed once created.

In summary, matrix fields provide modular flexibility whereas table fields offer simple spreadsheet-style data structuring. The choice depends on use case requirements.

Matrix vs Categories or Tags

Matrix fields differ significantly from Craft's categories and tags for content modeling:

Categories and tags apply standalone metadata labels to entries. Matrices create relationships between structured content blocks.

Categories have fixed attributes like title and uri. Matrix blocks contain custom fields like text, images etc.

Categories can only be selected - they do not encapsulate content. Matrix blocks hold modular content.

In summary, matrices enable rich, structured content definition. Categories/tags provide simple scalar metadata designation only.

Matrices would be preferred for complex relationships like a recipe ingredient matrix. Categories suffice for basic attributes like recipe difficulty levels.

When to Use Matrix vs Standard Fields

There are a few core use cases where matrix fields are preferable over standard Craft fields:

For modular or repeating content units like accordions, tabs and multi-section pages, matrices provide flexibility not possible in fixed fields.

For multi-step processes or complex multi-part forms, matrix fields enable better segmentation and guidance.

For nested or hierarchical data with relationships like charts or product specs, matrices model the connections better.

However, for simple singular content like page titles or metadata, standard fields remain ideal.

In summary, matrix fields truly excel at flexible, structured or modular content modeling where traditional fixed fields would become restrictive or convoluted. But for unstructured singular data, standard fields often suffice. Understanding these core strengths guides appropriate selection.

Shape April 2022 HR 202
Andy Golpys
- Author

Andy has scaled multiple businesses and is a big believer in Craft CMS as a tool that benefits both Designer, Developer and Client. 

Share
Feedback
Show us some love
Email Us
We usually reply within 72 hours
Agency Directory
Submit your agency
Affiliate Partners
Let's chat