New auto-collapsing menu



Reading time: 1 minute

In my previous version of the auto-collapsing (nested) menu I chose to avoid Hugo’s subsections. However, due to an update of the breadcrumbs, I was motived to test the possibility to create a nested menu based on sections and subsections. I succeeded and the code became much cleaner/shorter and simpler, especially due to the ‘.Ancestors’ variable. The way to determine if a page is ‘active’ is done through the following code:

{{ if or (in $.ancestors .) (eq $.curRelPermalink .RelPermalink) }}active{{ end }}

To check if it has children we simply check the length of the .Pages variable:

{{ if len .Pages }}haschildren{{ end }}

Hopefully you like this new approach for a nested auto-collapsing menu!

Fenix & Joost