I have pages structure with grandchildpages (03.site->01.site->01.site) and I created dropdown-menu. I have a problem with loop in child pages with own children because foreach have returned only one page from page collection (last page in the array of children pages precisely) in dropdown submenu.
This is my code:
{% for p in child.children %}
<div class="dropdown-menu">
<a href="{{p.url}}">{{p.title }}</a>
</div>
{% endfor %}
@pawel I have been staring at it for some time but could’t find an obvious issue why the 3th loop wouldn’t return any child pages.
A few questions come to mind looking at the code…
Questions with respect to looping:
Are you sure the 3th level really returns multiple pages?
Are all child pages numbered?
Do the pages perhaps have a frontmatter like ‘visible: false’?
Have you tried dumping the ‘p’ child using {{ dump(p) }} and watch the number of children it has? (Need to switch on the debugger in ‘system.yaml’ for that)
What does the generated HTML look like?
Could it be the js/css does not display 3th level?
As a side note: Wouldn’t a looping/recursing macro be a bit more elegant?
Questions with respect to HTML:
Where is the most outer <ul>
Shouldn’t the most inner loop be embedded in a <ul>? And each item withing a <li>?
Should the <div class="dropdown-menu"> surrounding the most inner anchor really be used?
I didn’t solve it yet. I have written pages using Bootstrap. It’s worked perfecly, 3th level menu especially.
I added successfully own css styles to Grav. Next I created pages structure via admin panel in Grav. All child pages are ordered and visible: true.
I have dumped this Twig children pages in the last-level folders. So this elements isn’t completely stripped from the page. They are only hidden, still space allocated on the DOM page. I have checked in Chrome Web Developer Tools and this children exist on own place.
@pavel Uhhh, please enlighten me… what exactly is not working about the menu at the moment?
By the way, is this nav intended to be used as the main navigation bar? Like the one used by Quark? If so, any reason why you prefer the nav component over the navbar component?
I use the Bootstrap 4 navbar component exclusively for the websites I create. What I like about the navbar component is its responsiveness i.e. it collapses into a menu button (the hamburger) when the website is shown on a mobile device. The nav component does not collapse, it wraps. The navbar also has space for branding.