Iterate through subsetions of a paticular section to display in a drop-down

Hello everyone,
I’m trying to improve the design of this sidebar menu I am working on. At the moment it looks like this:
unicef-sidebar

(Checkout the site: Cohorts)

The items appear as an unordered list with the subsections in a particular section also appearing. Doesn’t look that bad now but with time when the content adds the sidebar will be too long. I did a little redesign and this is what I am trying to achieve:
By default, it should look like this

And if the user wants to see the subsections, they can expand a section to view or click on the subsections which will be some sort of scrollbar.

What I am trying to do now is to find an easy way to iterate through the sections and in that iteration, iterate through the subsections of that section. That way I will be able to pass the subsections and have them display properly in a drop-down

Thanks.

1 Like

In the past I was rendering Nested Sections as a submenu of a Section with:


{{ with .Site.GetPage (printf "/%s" .Section) }} 
{{ $sections := .Sections }}
{{ range where $sections }}
<li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
{{ end }}
{{end}}

However there have been changes since then and I haven’t tested if the above construct still works with the latest Hugo version.