Is there any way to “hide” subcategories from topic lists and display the parent categories below the topic title instead?
My desired result is a root category with n subcategories. Those subcategories are not supposed to be displayed in the front end. They are only used to restrict access to the posts based on group membership.
In the topic list I would like to display the parent category below the topic title instead of the subcategory.
I thought about using tags, but unfortunately I can’t restrict access to the topics that way.
But if you only want this to happen for a specific parent category, you’d need to add more logic. I don’t know what would be the recommended way to do that, registering a handlebars helper?
Another approach could be to always show both category and parent links and then hide the ones you don’t want with CSS.
The parent categories are not on the default template, so yes, I guess you have to modify the template. At least I’m not aware of a lighter approach to achieve that.
There’s no site setting to modify templates, I’ll send you the code to try it out by DM.
In general, you should avoid full template overrides since they require maintenance - you have to run a diff and check what’s changed if a Discourse update breaks your theme.
What you can do, is take a step back and modify the data that gets passed to the template instead.
The topic-list-item is an ember component, so you can use api.modifyClass to make the changes you want
For example, here’s a snippet that will show the parent category badge in subcategory topics under the title. If the topic is in the main category, the code has no effect.
I edited the snippet above to reflect that change. All you need to do is to add the parent category ids to the targetCategoryIds array. You can find the category id by visiting the category page and checking the URL .
https://meta.discourse.org/c/support/6
“6” at the end of the URL above is the id for the support category here on Meta.
@Johani Where exactly do I put this code snippet?
I tried putting it into the </head> and header part of my theme component where I store all my CSS. But then the topic list is cut off exactly where the first affected topic from the subcategory is supposed to be listed.