2

I'm looking for a way to do rapid development (i.e. not manually using the UI to create one field at a time). So if you have a page which requires multiple similar fields you can quickly add them?

Most of a web pages I build are componentized so all fields are all variations of a base component - (example in screenshot below):

enter image description here

What you could do here (please correct me if im wrong):

  1. create a individual field in craft for each of these sections. So there would be 3 (as two of the fields are being used on different pages) - but:

a) If I need to use the same section multiple times on the page i.e. use the base field at the top of the page and bottom of the page then I cannot duplicate it (or just reuse it at the top and bottom), I'd need to create a brand new field - this feels very strange and like my process is wrong as its not DRY and leads to multiple fields - is there any documentation on how you should approach this?

I've seen reference to a wordpress plugin for this type of work: https://www.advancedcustomfields.com/

I'm not comparing caft and wordpress - I don't mind using the UI if thats the indended system and just making alot of fields, I'm just trying to find a answer to if this is the correct system instead of constantly thinking im creating alot of technical debt for a future developer.

Thanks - W

1 Answer 1

1

Sounds like you're looking for Matrix Fields. A matrix field allows you to create repeatable content blocks of varying types. This is different from a simple table (repeater) field since you can define several different block types – for example, one block type List and one block type Text. The editors can then create and arrange multiple block types as they see fit.

Check out the documentation on Matrix Fields to get started.

Note there are also other some plugins available that provide similar field types with some difference. Most notably the Neo plugin, which reuses your existing fields – meanwhile, the Matrix fields requires you to create fields in its own configuration, and separately for each block. Also, the Neo plugin allows you to create nested blocks, which Matrix can't at the moment.

10
  • Hi thanks for the info - I don't think that allowing any content editor to add new blocks or remove blocks with a matrix field is the correct workflow. I have tried to work out a solution using - Matrix > nested super table - super table > nested matrix - matrix > nested super table > nested matrix.... (these didnt work). I have seen the Neo plugin, which might be the way to go, but I was hoping to figure out what is the off the shelf P&T way to handle this type of issue? Is it just to create multiple fields, if so is there a way to do this faster like a json upload or something
    – Wally
    Mar 15 at 9:11
  • If you know of any docs you could point me to about how to handle workflow in Craft that would be great - i've been looking for a solid answer to this issue for an embarrassing amount of time - so I might have mis understood the way Craft operates
    – Wally
    Mar 15 at 9:13
  • 1
    @Wally I don't really understand the problem you're trying to solve. If it's about allowing for reusable content blocks, any combination of Matrix, Super Table and Neo fields will do fine. If it's about having a static content model with multiple fields – well, you just create those fields. Not worth it to go to elaborate setups or plugins just to save on some clicking in the UI. Though I think Matrix would be a good fit for your situation, maybe you just need to rethink your content approach a bit.
    – MoritzLost
    Mar 15 at 9:16
  • Thanks again for the reply - Ok I think its going to be a case of just creating static field types via the UI for each section for each page - I am a bit surprised that such a manual process is required for fields that have already been created (but i've only started to question it when looking at ways to slim down development time) - I have just trialed NEO this solves the ability to reuse already created fields.
    – Wally
    Mar 15 at 9:49
  • 1
    It's not really a separate answer to this one already given, merely an extension of it: you can use a matrix field to build up your body of content using different block types - one of those block types could be called "Component" or "Widget" and consist of an Entries selector field where you select an entry from a "Components" section to be output. The component can be reused in multiple blocks in the same entry, or across different entries. Entries in the components section can each be their own Entry Type to allow for unique field sets per component. Mar 15 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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