I tried this code from the cookbook but it doesn’t even render at all. No nav no ul.
<?php
$items = false;
// get the open item on the first level
if($root = $pages->findOpen()) {
// get visible children for the root item
$items = $root->children()->listed();
}
// only show the menu if items are available
if($items and $items->isNotEmpty()):
?>
<nav>
<ul>
<?php foreach($items as $item): ?>
<li><a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>"><?= $item->title()->html() ?></a></li>
<?php endforeach ?>
</ul>
</nav>
<?php endif ?>
If I take away the if clause “isNotEmpty”, I get a nav element and the ul, but no li.
How can I have no pages for the script to find, when I actually do have them?
If I use my own menu snippet - which is pretty much the one from the docs - it works. I just need a sub menu thing for one page/ item.
I guess, I misunderstood this menu example in that, I am not sure what kind of menu this is.
Yes, there is just one page with a subpage/ child. But I need to show the submenu if a user clicks on the menu item that has a subpage. But of course the whole menu should be visible on every page, not only on a page that has children. So - I somehow misunderstood something.