Ok, the module code filters by visible modules, so they should be visible. Then you need to change your menu code, you can use the not() method with a collection of pages to exclude from the menu.
You can filter by template (all module templates start with module.).
But even easier: You can use the second, recommended approach and create a subpage called modules for each page where you need modules. This modules page can be invisible. Only the individual modules inside that directory need to be visible, but because of the hidden parent they won’t appear in menus.
Hi @lukasbestle,
did you mean something like this:
// get all children for the current menu item accept modules
$children = $item->children()->visible()->filter(function($child) {
if(!str::startsWith($child->template(), 'module.')) {
return $child;
}
});
// get all children for the current menu item except modules
$children = $item->children()->visible()->filter(function($child) {
return !str::startsWith($child->template(), 'module.');
});
The filter function only needs to return true or false, so there is no need for the if.
just to end this post. In the end I used the second, recommende aproach and put all modules inside a invisible subpage named modules. This is the clean and easy way.