Skip to content

Commit 6142bc7

Browse files
committed
tpl: Fix theme overrides when theme has old layout setup (e.g. _default)
Fixes #13715
1 parent e6574cf commit 6142bc7

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

tpl/tplimpl/templatestore.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,12 +1133,21 @@ func (s *TemplateStore) insertTemplate2(
11331133
tree.Insert(key, m)
11341134
}
11351135

1136-
if !replace {
1137-
if v, found := m[nk]; found {
1138-
if len(pi.Identifiers()) >= len(v.PathInfo.Identifiers()) {
1139-
// e.g. /pages/home.foo.html and /pages/home.html where foo may be a valid language name in another site.
1140-
return nil, nil
1141-
}
1136+
nkExisting, existingFound := m[nk]
1137+
if !replace && existingFound && fi != nil && nkExisting.Fi != nil {
1138+
// See issue #13715.
1139+
// We do the merge on the file system level, but from Hugo v0.146.0 we have a situation where
1140+
// the project may well have a different layouts layout compared to the theme(s) it uses.
1141+
// We could possibly have fixed that on a lower (file system) level, but since this is just
1142+
// a temporary situation (until all projects are updated),
1143+
// do a replace here if the file comes from higher up in the module chain.
1144+
replace = fi.Meta().ModuleOrdinal < nkExisting.Fi.Meta().ModuleOrdinal
1145+
}
1146+
1147+
if !replace && existingFound {
1148+
if len(pi.Identifiers()) >= len(nkExisting.PathInfo.Identifiers()) {
1149+
// e.g. /pages/home.foo.html and /pages/home.html where foo may be a valid language name in another site.
1150+
return nil, nil
11421151
}
11431152
}
11441153

tpl/tplimpl/templatestore_integration_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,23 @@ All.
11031103
b.AssertLogContains("unrecognized render hook")
11041104
}
11051105

1106+
func TestLayoutOverrideThemeWhenThemeOnOldFormatIssue13715(t *testing.T) {
1107+
t.Parallel()
1108+
1109+
files := `
1110+
-- hugo.toml --
1111+
theme = "mytheme"
1112+
-- layouts/list.html --
1113+
layouts/list.html
1114+
-- themes/mytheme/layouts/_default/list.html --
1115+
mytheme/layouts/_default/list.html
1116+
1117+
`
1118+
1119+
b := hugolib.Test(t, files)
1120+
b.AssertFileContent("public/index.html", "layouts/list.html")
1121+
}
1122+
11061123
func BenchmarkExecuteWithContext(b *testing.B) {
11071124
files := `
11081125
-- hugo.toml --

0 commit comments

Comments
 (0)