Hello,
From menu.go:
// MenuEntry represents a menu item defined in either Page front matter
// or in the site config.
type MenuEntry struct {
URL string
Page *Page
Name string
Menu string
Identifier string
title string
Pre template.HTML
Post template.HTML
Weight int
Parent string
Children Menu
}
// Menu is a collection of menu entries.
type Menu []*MenuEntry
// Menus is a dictionary of menus.
type Menus map[string]*Menu
I see that Menus is a map and MenuEntry is a struct, but I don’t understand what []* is…
- Doing
{{ range $i, $j := .. }}over.Site.Menusworks- Each of the
$jelements in that range would be of typeMenu.-
But I am lost how to loop through each item in
Menucollection…rangedoes not work.- Once above step is solved, I can easily print the
MenuEntrystruct elements.
- Once above step is solved, I can easily print the
-
But I am lost how to loop through each item in
- Each of the
Trying to range through Menu gives errors like:
ERROR 2018/02/05 23:38:11 Error while rendering "home" in "": template: /home/kmodi/stow/pub_dotfiles/emacs/dot-emacs.d/elisp/ox-hugo/doc/themes/hugo-alabaster-theme/layouts/index.html:20:8: executing "/home/kmodi/stow/pub_dotfiles/emacs/dot-emacs.d/elisp/ox-hugo/doc/themes/hugo-alabaster-theme/layouts/index.html" at <partial "sidebar/sid...>: error calling partial: template: theme/partials/sidebar/sidebar.html:18:11: executing "theme/partials/sidebar/sidebar.html" at <partial "sidebar/men...>: error calling partial: template: theme/partials/sidebar/menu.html:63:3: executing "theme/partials/sidebar/menu.html" at <partial "debugprint....>: error calling partial: template: partials/debugprint.html:38:11: executing "partials/debugprint.html" at <partial "debugprint....>: error calling partial: template: partials/debugprint.html:38:11: executing "partials/debugprint.html" at <partial "debugprint....>: error calling partial: template: partials/debugprint.html:37:13: executing "partials/debugprint.html" at <$value>: range can't iterate over {/doc/why-ox-hugo/ Page("Why ox-hugo?") Why ox-hugo? early_questions why-ox-hugo 3001 []}
I am using this debugprint.html partial.
You can recreate the above error on any site with menus by doing below after copying the above linked partial and putting below anywhere in your layout:
{{ partial "debugprint.html" $.Site.Menus }}