Option to hide 3rd level categories on the categories homepage without losing the layout

This is a reasonable request, it can be hard to balance the layout of the /categories page if there are only a few categories with multiple levels of subcategories.

We really don’t want people using modifyClass anymore because, as you mentioned, keeping that sort of override maintained can take some development effort.

We have some newer methods of customization that we can work with now that are easier to keep stable. In this case a value transformer can help. I’ve just added one here that will be available in updates soon: DEV: Add a category-list-subcategories value transformer - Pull Request #42804 - discourse/discourse - GitHub

The simple demo is something like this:

api.registerValueTransformer(
  "category-list-subcategories",
  ({ value, context }) =>
  context.page === "categories" && context.category.level >= 1 ? [] : value
);

This will only show a single level of subcategories. There are other options available using the transformer now, so I’ve put together a theme component that we can maintain to support them.

So once Discourse is updated you can install this to control how many subcategories display on /categories and some other category lists:

Set Categories page depth to 2 to hide all the grandchild categories.

2 לייקים