Category and subcategories

Hello, it’s been several days that I have been puzzling to find a solution to my problem …
I am building a new blog that contains categories and subcategories.
I have a main “blog” page which contains all the articles.

Something like:

  • /Blog
    • article01
    • article02
    • article03

Each article is defined with a main category:

  • /Blog
    • article01 - category: tests
    • article02 - category: tutorial
    • article03 - category: tutorial

An article can also have a sub-category:

  • /Blog
    • article01 - category: tests
    • article02 - category: tutorial
    • article03 - category: tutorial / beginner (or advanced / expert / etc…)

However I need to be able to create and edit the categories in the panel: blog.yml, so with the structure fields it’s good:

category:
  type: structure
  fields:
    name:
      label: Category name
      type: text
    subcategory:
      label: Sub-Category
      type: structure
      fields:
        name:
          label: Sub-Category Name
          type: text

So I still have to find a way to be able to select a subcategory in the same way as this: Conditional fields.

I imagine it like this:
When editing the article I select my category with a “select” field.
If I select the “tutorial” category, a second “selec” field appears so that I can select the subcategory.

Here I tried to be as clear as possible for the explanation, I had stopped coding for a long time and I am completely lost today and I see that Kirby has evolved a lot. :slight_smile:

Since the entries in the structure field are not predefined but can be changed by the user, you cannot really create the select fields for the subcategories in advance using when. And you would probably end up with a lot of different select fields depending on the entry.

In Kirby 3.6 you will be able to create such blueprints dynamically (Add programmable blueprints recipe by texnixe · Pull Request #1455 · getkirby/getkirby.com · GitHub), but you would still end up with multiple fields for the subcategory selects.

It would be better if the subcategory options would change depending on the value selected in the first field, but to achieve that, you would have to create a custom field combination, where you would be able to listen to changes in the first field and react on that to change the options selectable in the second field.