I’m just beginning to learn Grav because I need to port several websites from a dying CMS.
For a drop-down menu I use the approach from the ‘Photographer’ theme as explained in ‘Loop to add children pages as dropdown’.
To detect children, it uses:
In my setup I use modular pages and ‘normal’ child pages.
The filter above does take both of them as children, but in my menu I only need the latter ones of course. In the menu on the page the modular children do not appear, but in the source there are empty <ul> </ul> tags.
How can I avoid this?
*1 - these are modules of a modular page and should not appear in the dropdown menu and the modular page should not get param ‘submenu’.
*2 - these are children of a page and shall appear in the dropdown menu as 2nd level; the parent page shall get the param ‘submenu’.
Both of them are equally considered to be children of their parent by “p.children.count”.
The “real” ones are shown in the menu in 2nd level with their menu title, the “wrong” ones are not, but their parent is marked as having a submenu.
@bigboy, Ah, thanks for the updated information. I do get a better picture of the overall situation now.
I think the issue is related in the Twig code. You are looping through all children, while you only want the visible children.
If you’ve only taken the above snippet from the Photographer theme, you may have missed the test {% if p.visible %} in its navigation template.
I still don’t understand why that is not working as expected, i.e. every menu item is marked as parent, despite the set visible filter.
Anyway, if I follow your advice and replace the 5th line as follows
everything is OK! Great!
This allows me to use a pure HTML/CSS multilevel drop-down menu (no JavaScript) in my websites.
Thank you for this “magic”(?) tip.