1

A little background first; I'm coming from WordPress, along with the Advanced custom fields (ACF) plugin, so my thinking behind this may not be the best way in Craft.

In ACF I usually set up a field set that consists of an outer repeater field, with a nested flexible content field inside (much like the Matrix field in Craft). Within the repeat field, there are a couple of options that controls the appearance of a section, such as a background colour/image. This is also used in my template to differentiate where a <section> starts and ends, and often has styles associated to style the overall section. Anything within the flexible content fields is contained within this.

Then, within the flexible content field, I define my layout types (title block, two column text, text with image, etc.). An image to describe the layout structure if my description is a little confusing: Sections

I'm looking to create a similar sort of set up with Craft. Without an outer repeater field, I'm struggling to think how to achieve the "section" container. What would be a way to achieve this sort of thing?

Thanks!

3
  • Hmmm - thats a tricky one. All I can think of is to have a block called 'section', which in your templates, you use to create your opening and closing tags. Right now, there's no matrix-in-matrix, which I think is what you're after, if you're looking to replicate ACF.
    – crawf
    Mar 5, 2015 at 9:53
  • This looks to be the route I need to go down. I may need to use a "section start" and a "section end" to simplify logic as much as possible. A little more work for the client, but with a little training it should make sense. Mar 5, 2015 at 10:52
  • This related answer from Brandon might help you avoid needing the start + end blocks craftcms.stackexchange.com/a/6739 Mar 5, 2015 at 11:01

1 Answer 1

6

I'm not familiar with ACF, but if you're looking for blocks-within-blocks, you could use the Neo plugin/fieldType. It allows you to define blocks, and then have nested blocks. It allows for decent management of blocks, too, so that you have children of specific parents.

For example: You could have the following blocks/content types:

  • Copy
  • Card
  • Image slider
  • Form
  • Ad Unit
  • Related Content

And then the following layouts and components:

  • Two-column
  • Three-column
  • Single column w/ Sidebar
  • Column
  • Sidebar

The Neo fieldType would allow you to make block groups, and then allow the content blocks to be limited to certain layout blocks. It would look like this (demo only, not fully configured):

The layouts are selectable at the top level. You need these to target template files (or at least it makes it easier, IMHO).

enter image description here

The layouts can only have columns or sidebars. The two- and three-column only have columns, while the single has column and sidebar.

Note: Currently blocks are only limited on the page level and not the block level, meaning if you set the max number of columns to 1, you'll only be allowed one column per entry.

enter image description here

The column block has the main content types, while the sidebar block has the sidebar content types.

enter image description here

1
  • Thanks Ian DeRanieri. A very useful explanation of using Neo for this sort of 'templated layout'. My only question is, considering you can't limit the amount of column blocks in one of your layout blocks, did you end up just relying on the user to only add the appropriate number of column blocks to each layout block, or did you use some CP JavaScript to achieve it?
    – Tim Everts
    Jan 16, 2018 at 0:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.