Skip to content

Commit fd38aee

Browse files
committed
Support menus as maps in content adapters
Fixes #13384
1 parent d25f7ec commit fd38aee

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,34 @@ Footer: {{ range index site.Menus.footer }}{{ .Name }}|{{ end }}|
653653
)
654654
}
655655

656+
// Issue 13384.
657+
func TestPagesFromGoTmplMenusMap(t *testing.T) {
658+
t.Parallel()
659+
660+
files := `
661+
-- hugo.toml --
662+
disableKinds = ['rss','section','sitemap','taxonomy','term']
663+
-- content/_content.gotmpl --
664+
{{ $menu1 := dict
665+
"parent" "main-page"
666+
"identifier" "id1"
667+
}}
668+
{{ $menu2 := dict
669+
"parent" "main-page"
670+
"identifier" "id2"
671+
}}
672+
{{ $menus := dict "m1" $menu1 "m2" $menu2 }}
673+
{{ .AddPage (dict "path" "p1" "title" "p1" "menus" $menus ) }}
674+
675+
-- layouts/index.html --
676+
Menus: {{ range $k, $v := site.Menus }}{{ $k }}|{{ end }}
677+
678+
`
679+
b := hugolib.Test(t, files)
680+
681+
b.AssertFileContent("public/index.html", "Menus: m1|m2|")
682+
}
683+
656684
func TestPagesFromGoTmplMore(t *testing.T) {
657685
t.Parallel()
658686

resources/page/pagemeta/page_frontmatter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type PageConfig struct {
105105
Cascade []map[string]any
106106
Sitemap config.SitemapConfig
107107
Build BuildConfig
108-
Menus []string
108+
Menus any // Can be a string, []string or map[string]any.
109109

110110
// User defined params.
111111
Params maps.Params

0 commit comments

Comments
 (0)