3 Category Levels (trimChildren helper)
-
Our existing forum structure includes an extra level, which we use as a section heading. While this works this prevents our theme from showing the subcategories underneath.
I have tracked this down to the helpers.trimChildren function, which sets the children variable to undefined as a way of limiting the depth. As we need as extra depth level is there any way of overriding this function without having to resort to modifying core code?
You can see in these screenshots. The first screenshot is how it looks normally and the second is how we want it to look.
-
I will take a look at this, maybe try to make the depth limit configurable so you can set it to 2 or more.
Until I add that in you can override that function in your plugin or theme with
const helpers = require.main.require('./src/controllers/helpers'); helpers.trimChildren = function (category) { if (Array.isArray(category.children)) { category.children = category.children.slice(0, category.subCategoriesPerPage); } };
Keep in mind this will cause the entire category tree to be returned and might make your /categories page load slower if there are a lot of nested categories.
-
Thanks for response. Exactly what I was looking for
-
@Matthew-Price are you using the
section
option on thewelcome centre
category?Maybe I can check this setting when trimming the depth and adjust accordingly.
-
@Matthew-Price take a look at https://github.com/NodeBB/NodeBB/commit/0bec52bc19405fe0c6ef8cdcfd834518ac6b9b8f.
Let me know if it handles your use case.
-
@Matthew-Price Yeah I've made this change on our develop branch, if category is marked as section then it won't trim it's second level children.
-