Combine Menu & Tags in a single range

Gday Hugo Forums,

Was hoping someone could assist me in selecting menus in a $.Site.GetPage manor, I need to list both tags and pages from a menu in a single area, not fussed on weight as of yet. How would I go about doing so?

Attempted the following…

{{ $pages := (.Site.Menus.tertiary.Menu).Pages }}
{{ $tags := ($.Site.GetPage "taxonomy" "tags").Pages }}
{{ range union $tags $pages }}
<li class="col-6"><a href="{{ .URL }}">{{ .Title }}</a></li>
{{ end }}

But I can’t seem to find a way I can pull .Pages from a menu, any ideas? :slightly_smiling_face:

What does your menu configuration look like? Better yet, do you have your site code somewhere we can have a look at?

Sadly i’m not at liberty to disclose the source of this.

However it’s nothing special, literally just being defined per page in markdown files and default, i.e nothing fancy in the config.toml

So, basically, this won’t work.

You can try iterating over all the menu items, then check if the item is linked to a .Page. If it is, collect into a slice.

{{ $menuwithpage := slice }}
{{ range .Site.Menus.main }}
  {{ with .Page }}
    {{ $menuwithpage = $menuwithpage | append . }}
  {{ end }}
{{ end }}

This probably also doesn’t work. Instead:

{{ $union := union $tags $pages }}
{{ range $union }}