The DatoCMS Blog

The wait is over: Nested Blocks are here!

Posted on October 11th, 2021 by Stefano Verna

Friends, it's with infinite joy that we can announce the general release of the most requested feature in the history of DatoCMS: Nested Blocks!

This massive change exponentially increases the expressiveness of your content model, and allows patterns and scenarios that before today were simply impossible to achieve.

What Blocks are, in the first place?

Blocks are a concept unique to DatoCMS, and they allow to define complex and repeatable structures that can be embedded inside records.

You can use blocks inside two different DatoCMS fields, to achieve different results:

  • Using Structured Text fields, you can create media-rich content by interleaving free-form text and blocks representing CTAs, quotes, image galleries, infographics, etc;

  • Using Modular Content fields, you can create custom page-builders to let your editors combine different blocks together like Lego pieces to build any kind of dynamic layout (especially useful for landing-pages).

Blocks keep your projects clean by avoiding orphaned records and mantain your content 100% structured without having to rely on arbitrary JSON structures. Blocks can enforce validations on their fields, and you can reference other records/assets without workarounds.

In the end, this all means simpler data migrations, integrity of data and full control of your own content, which is what we care about the most.

Why Nested Blocks are so important?

While a single level of blocks in a Modular Content/Structured Text field is often more than enough to represent real-world pages, there are specific situations where, well... you need to go deeper. An example that often comes up is wanting to model A/B tests with blocks. This requirement alone already adds one additional level of nesting to the original problem you had on your plate.

But even considering a page that today might not need nested blocks... what about tomorrow? Requirements often change over time, and no one likes a sword hanging over their head.

These thoughts have often led to clients preferring a sub-optimal solution, such as a Link field, for situations that were designed specifically for a Modular Content field. Better to have potentially orphaned records, unnecessary confusion, and a lack of cleanliness in the schema... than the possibility of having to completely restructure the schema for a small change in a layout!

Well, the dark times are over!

So, what changed?

You can now add Modular Content fields to your blocks. In this example, we're building a Pricing Table block for our landing pages, which in turn contains Pricing Tier blocks:

Here's the final result, on the content editing side. Our landing page can add a Pricing Table section, and insert the different tiers inside of it:

Similarly, you can now embed inner blocks in Structured Text fields belonging to blocks. In this example, we're creating a Slideshow block, containing an arbitrary number of Slide blocks, that can be included in our main article content:

And again, final result for the editor:

Try them yourself!

Nested blocks are already available on all plans and projects. The maximum depth you can reach is 3 levels of blocks — which we think should cover every possible need — but if your project needs something special, just contact us and we can setup custom limits for you.

Now we can't wait to see what you'll create with nested blocks. Please share your work on our Community, we'd love hear your thoughts and feedback!

Start using DatoCMS today
According to Gartner 89% of companies plan to compete primarily on the basis of customer experience this year. Don't get caught unprepared.
  • No credit card
  • Easy setup
Subscribe to our newsletter! 📥
One update per month. All the latest news and sneak peeks directly in your inbox.
support@datocms.com ©2024 Dato srl, all rights reserved P.IVA 06969620480