Support menus as maps in content adapters

Fixes #13384
This commit is contained in:
Bjørn Erik Pedersen 2025-02-13 11:42:42 +01:00
parent d25f7ec172
commit fd38aee694
2 changed files with 29 additions and 1 deletions

View file

@ -653,6 +653,34 @@ Footer: {{ range index site.Menus.footer }}{{ .Name }}|{{ end }}|
)
}
// Issue 13384.
func TestPagesFromGoTmplMenusMap(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
disableKinds = ['rss','section','sitemap','taxonomy','term']
-- content/_content.gotmpl --
{{ $menu1 := dict
"parent" "main-page"
"identifier" "id1"
}}
{{ $menu2 := dict
"parent" "main-page"
"identifier" "id2"
}}
{{ $menus := dict "m1" $menu1 "m2" $menu2 }}
{{ .AddPage (dict "path" "p1" "title" "p1" "menus" $menus ) }}
-- layouts/index.html --
Menus: {{ range $k, $v := site.Menus }}{{ $k }}|{{ end }}
`
b := hugolib.Test(t, files)
b.AssertFileContent("public/index.html", "Menus: m1|m2|")
}
func TestPagesFromGoTmplMore(t *testing.T) {
t.Parallel()

View file

@ -105,7 +105,7 @@ type PageConfig struct {
Cascade []map[string]any
Sitemap config.SitemapConfig
Build BuildConfig
Menus []string
Menus any // Can be a string, []string or map[string]any.
// User defined params.
Params maps.Params