Issue with ``where`` that shows up with hugoThemes

I actually had a problem with site not matching the page context’s .Site with the debug tables (was needing to compare the top-level passed in site to the current page’s .Site context in a cheap effort to avoid infinite recursion when expanding variables as an optional feature – that really hasn’t worked out the best, and mostly it’s best to just look at the current page context with the debug table at the moment. The expanding more levels down needs some love yet).

That made me leery of site, but that’s a special case and not relevant to this more usual case (and would save some contortions).

[trim noise]

All I’m really trying to do is end up with a combined set of list items (navigation links) that include the mainSections and main menu items without duplication. I wonder if I could create two slices of the results of GetPage on mainSections and the main menu and using some set logic to get the non-duplicating union. I’m thinking I may also want the top level RegularPages, but hat is less certain.

Bwah hah hah! (I hope…it seems to work for my tests of without menu, with duplicated item, and with no duplicates – am I missing something?)

{{- $curPage := . -}}
{{- $mainMenu := site.Menus.main -}}
{{- $sections := where site.Home.Pages "Section" "in" site.Params.mainSections -}}
{{- $menuPages := (slice) -}}
{{- range $mainMenu -}}
    {{- $menuPages = $menuPages | append (where site.Home.Pages "RelPermalink" .URL) -}}
 {{- end -}}
 {{- range (union $sections $menuPages) -}}
     <li class="list-item-test-min{{- if eq $curPage . }} current-menu-is-test-min{{- end -}}">
         <span class="link-wrapper-test-min"><a
            href="{{- .RelPermalink -}}" class="link-test-min">{{-
            partial "return-helpers/title" . -}}</a></span>
    </li>
{{- end -}}

@davidsneighbour I don’t suppose where can use eliminate the need for the range on mainMenu as far the .URL goes?