1

I need only 2 main categories, A and B, and both can have unlimited subcategories. Ideal would be to split these into groups but how can an editor choose between groups AND only select or create a category?

I could setup a checkbox field which asks is this A or B but this then needs to be linked to the category groups and might make the template tags to call the data unnecessary complicated.

What's the craft-way todo this?

2

A rather sneaky solution to your issue could be to create a matrix field that has one block type per category group. Each of those block types then could contain a single category field with the category source set to the corresponding category group. Limit those category fields to 1 category each and then limit the matrix field to one matrix block.

This way your editors will be able to select only one of the matrix block types and that block type will limit the categories to the selected group.

If you need this for some custom markup wizardry in your templates, make sure you understand variable scoping in Twig loops if you're trying to set some variable value while looping through your matrix data.

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.