The Matrix field is one of the most powerful features of Craft CMS. It allows developer to create reusable blocks of fields that can be used to construct complicated page layouts. But what if we want to go deeper and define reusable blocks within reusable blocks? There are multiple ways to achieve this.
Table field within the Matrix field #
The table field itself is already a kinda budget version of the Matrix field. It can have its own field layout, but it does not allow some sub-fields - for example, these that provide relationships to elements, like asset field or entry field. While Matrix allows for different types of blocks - with table you only get one type of table row. Hovewer, if you are fine with such limitations, I strongly suggest using this solution over relying on third-party plugins.
Field layout of asset source #
Assets sources can have their own field layouts, which means that if you place asset field in Matrix block, asset itself takes role of sub-block. Such a solution however is not really that user friendly. To display fields of asset, you need to click it so popup with asset details shows up.
Super Table plugin #
Super Table plugin adds new field - one called "Super Table". This field works pretty much like normal Matrix, but you can also use the regular Matrix in Super Table block field layout. This means that you can achieve two levels of depth (blocks in blocks), and if you include table field inside the Matrix field that itself is inside Super Table field - three levels (blocks in blocks in blocks).
Super Table is free and is good solution for budget projects when the functionality of "table within a Matrix" is not enough.
Neo plugin #
Neo plugin is the most advanced solution from all presented in this article. This however comes with the price - plugin license costs 49 dollars.
Instead of defining fields for each block (like with regular Matrix), Neo allows you to use already existing fields - just like you use fields in Craft entry type layouts. You can even place already existing Matrix field within Neo block.
But the most powerful feature of Neo is that its blocks can be nested - indefinitely it seems (well, there probably is some kind of limit). So, you can have a block, within a block, within a block, within a block, etc.
Developers can also set up how blocks relate to each other - whether the specific block can be child of another specific block, how often block can be used or which "neighbours" can it have.
Conclusions #
- If you don't need element relation fields in your sub-blocks or multiple types of sub-blocks - use table field within native Matrix field.
- If you are on a budget - use Super Table.
- If you need an advanced solution - use Neo.
Remember that basing structure of your data on third-party plugins always comes with the risks:
- There could be problems with updating system and migrating old content when a new major version of Craft is released. Such bugs may be hard to solve.
- Other plugins that provide their own fields can cause conflicts and unpredictable bugs.
- You are locking your website into a plugin - if plugin do not get updates, you will not be able to update your website too. That's because because plugin might not be compatible with new version of system.
In the past, that's what happened with the previous version of Neo - when Craft 3 was released, Neo plugin wasn't updated for few months. However, currently such situation is not that likely - both Neo and Supertable are very popular plugins and Neo gives its creators a steady stream of revenue - and you don't kill the goose that lays the golden eggs.
Future #
Sooner or later, Craft will get its own native nested Matrix field - here's a link to discussion on github about this feature. Interestingly, there are mentions about solution for migrating Neo and Super Table content into future native nested Matrix.