Hi, I would like to hide some parent menu items. How does it work? Do I have to write something in page blueprint to make it hidden in menu? Best would be to have a checkbox field in panel in that page editing, so that client manage himself.
Also sometimes would need, that page, that is first level, would be displayed as child (2 level) in menu. How is it possible to do?
I’d probably use a nested structure field to fully control the menu manually (with pages fields inside the structure)
fields:
type: fields
headline: Menu
fields:
menu:
type: structure
fields:
mainitem:
label: Main Menu Item
type: pages
query: site.index # you can adapt this query to exclude pages that shouldn't appear in the main menu, like the error page or subpages etc.
level2:
type: structure
fields:
subitem:
label: Child Menu Item
type: pages
The toggle field approach works fine if you just want to include/exclude pages from the navigation. But if you want to control the level where in the navigation an item appears, or the order in which the items appear in the navigation manually, the toggle field approach is not enough.
If it’s: <li class="nav-item <?php e($menu1->isOpen(), 'active') ?> dropdown">
then parent item always gets active class, even when it’s not open.
also tried: <li class="nav-item <?php e($p->isOpen(), 'active') ?> dropdown">
it doesn’t change anything.
With different method works fine, for example:
<?php
// nested menu
$items = $site->pages()->filterBy('intendedTemplate', 'in', ['about','landing','default'])->listed();
// only show the menu if items are available
if($items->isNotEmpty()):
?>
<ul class="navbar-nav mr-auto">
<?php foreach($items as $item): ?>
<li class="nav-item <?php e($item->isOpen(), 'active') ?> <?php if($item->children()->listed()->isNotEmpty()): ?>dropdown<? endif ?>
">
I take it you have read through the menu page in the cookbook? I find the Tree menu the most useful - its a snippet that keeps calling itself until it runs out of pages. You could probably adapt it to work with the structure field.
Yes, I was checking it, but as I understand it replicated the same structure, but in Bootstrap children and their wrapper are different than parents. And actually it’s only this class missing now, so hope can finish with current solution