I was trying to show only those pages in menu, that belong to certain templates:
$items = $site->pages()->filterBy('template', 'in', ['about','landing','default'])->listed();
Filters are working fine, but only ‘default’ is showing Partners parent page and Partners children. I think the first reason was, that I left template name “default” in Partners and Partners blueprints. But although I changed it now, also tried to delete parent page of Partner and children, and created them again, but it’s still displayed with ‘default’ filter. What can be the reason?
Here is full code for menu:
<?php
// nested menu
$items = $site->pages()->filterBy('template', '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 ?>
">
<?php if($item->children()->listed()->isEmpty()): ?>
<a class="nav-link" href="<?= $item->url() ?>"><?= $item->title()->html() ?></a>
<? endif ?>
<?php if($item->children()->listed()->isNotEmpty()): ?>
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?= $item->title()->html() ?></a>
<? endif ?>
<?php
// get all children for the current menu item
$children = $item->children()->listed();
// display the submenu if children are available
if($children->isNotEmpty()):
?>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<?php foreach($children as $child): ?>
<a class="dropdown-item <?php e($child->isOpen(), 'active') ?>" href="<?= $child->url() ?>"><?= $child->title()->html() ?></a>
<?php endforeach ?>
</div>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>