Search menu with Where?

Hi all,

I want to find just 1 branch of the menu, which is basically sibling pages to the current page. I’ve got all the pages in the same folder due to the CMS I’m using, so I don’t think I can use the Section functionality.

This works:

{{ range $.Site.Menus.main }}
  {{ if .HasChildren }}
    {{ range .Children }}
      {{ if eq .Parent "about-us" }}
        {{ .Name }}
      {{ end }}
    {{ end }}
  {{ end }}
{{ end }}

But is there a way to search the menu for “parent: about-us” in one go instead of iterating over everything?

I find it helpful to examine the data structure:

<pre>{{ jsonify (dict "indent" "  ") site.Menus.main }}</pre>

To get the children of about-us:

{{ $childrenOfAboutUs := (index (where site.Menus.main "Identifier" "about-us") 0).Children }}
<pre>{{ jsonify (dict "indent" "  ") $childrenOfAboutUs }}</pre>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.