What we’re looking forward to in Craft CMS 4

By Charlie,

March 2022

Insights
As a Craft CMS agency we were excited by the beta release of Craft 4 in March.

We’ve been using Craft for many years now due to it’s simplicity and flexibility. So when Pixel & Tonic released their first beta we were eager to check it out. This new version comes with lots of new features:

Conditional fields

It’s been a long time coming, however Craft 4 will finally give us conditional fields! This means we can show/hide fields based on whether or not they match a certain criteria.

Craft 4 will give us two types of conditions:

  1. Current User Condition

  2. Entry Condition

Craft Conditional fields

Being able to dictate which fields display based on these conditions can help us keep a clean and simple user interface for our clients.

Collections

Craft 4 is introducing Laravel Collections to work together with data arrays. Not only are eager loading elements returned as a collection now by default, you can also use the new ‘collect()’ function, instead of ‘all()’ to get your data.

This introduction is going to help us simplify our code making it cleaner and more readable. For example if we want to group entries together, based on their section, currently we’d need to do the following:

{% set entries = craft.entries()  
 .section(['news', 'webinars'])  
 .limit(10)  
 .all() %}  
 
{% set entriesGrouped = entries | group('section.handle') %}

There is nothing wrong with this, however using the Twig filter isn’t ideal. So with collections we can now group this with a Craft Function:

{% set entries = craft.entries()  
 .section(['news', 'webinars'])  
 .limit(10)  
 .collect() %}
 
{% set entriesGrouped = entries.groupBy('section.handle') %}

Collections are also great for eager loading assets. In Craft 3 we’d need to get the image url within the array, which sticks out as it doesn’t match other Craft queries, like this:

{{ entry.image[0].url() }}

In Craft 4, we can now call the Url like this:

{{ entry.image.collect().first().url() }}

Which is a much nicer method to get your image.

Custom Sources

In the Entries panel with Craft 3 you can customise the sidebar to rearrange the element sources and add custom headings. However in Craft 4 they’re introducing Custom Sources to the sidebar.

Custom sources will allow you to choose what kind of elements to display within that source, based on a limited set of conditions. This can help our clients find the pages they need quicker and more efficiently.

Craft Custom Sources

Element Index Filtering

Another welcome addition to filtering. This conditional filter can be found to the right on the entry index search bar.

Within this you can set multiple conditions to narrow down the entries you’re looking for, and then add the text that you want to search by. This will be really useful for sites that are content heavy with news entries for example.

Element Index Filter

Category Drafts

A small but welcome addition in Craft 4 is the ability to set Categories as drafts. On certain sites, where categories are used as landing pages, the ability to preview categories and save them as drafts is a great way to make the CMS more consistent for users.

Element Slideouts

Craft 3.7 introduced the new Editor Slideout UI. This meant you could add a new Entry from an entry field and fill in all the fields without leaving your current page!

In Craft 4 this has been developed even further so you can update everything from the slideout including:

  • Status

  • Post Date

  • Author

  • Expiry Date

  • Parent

This development means you can create multiple entries from one page, again simplifying the editing process.

These are just a few of the new features coming to Craft 4. We can’t wait to see it in action when it’s released later this year!

You can see all of the upcoming features on Craft’s Roadmap.