diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2025-04-20 10:59:40 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2025-04-20 12:55:18 +0200 |
commit | 088cd2f996bfbbdf4ed01cafa2c8101b3ea0e94e (patch) | |
tree | 5ed21f08e24a65a0782735ec18593f5119fab8ec | |
parent | a88b488181279befd50e1d127f9f67604f2f9854 (diff) | |
download | hugo-088cd2f996bfbbdf4ed01cafa2c8101b3ea0e94e.tar.gz hugo-088cd2f996bfbbdf4ed01cafa2c8101b3ea0e94e.zip |
tpl: Fix when layout specified in front matter and no match is found
Fixes #13628
-rw-r--r-- | tpl/tplimpl/templatedescriptor.go | 2 | ||||
-rw-r--r-- | tpl/tplimpl/templatestore_integration_test.go | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/tpl/tplimpl/templatedescriptor.go b/tpl/tplimpl/templatedescriptor.go index 8e4390fae..ca73c9f78 100644 --- a/tpl/tplimpl/templatedescriptor.go +++ b/tpl/tplimpl/templatedescriptor.go @@ -177,7 +177,7 @@ func (this TemplateDescriptor) doCompare(category Category, isEmbedded bool, oth w.w2 = weight2Group1 } - if this.LayoutFromUser == "" && other.LayoutFromTemplate != "" && (other.LayoutFromTemplate == this.LayoutFromTemplate || other.LayoutFromTemplate == layoutAll) { + if other.LayoutFromTemplate != "" && (other.LayoutFromTemplate == this.LayoutFromTemplate || other.LayoutFromTemplate == layoutAll) { w.w1 += weightLayoutStandard w.w2 = weight2Group1 diff --git a/tpl/tplimpl/templatestore_integration_test.go b/tpl/tplimpl/templatestore_integration_test.go index 32e1248fe..e59dad33a 100644 --- a/tpl/tplimpl/templatestore_integration_test.go +++ b/tpl/tplimpl/templatestore_integration_test.go @@ -1204,3 +1204,28 @@ layouts/_partials/comment.ru.xml b.AssertFileContent("public/ru/index.html", "layouts/_partials/comment.ru.html") // fail b.AssertFileContent("public/ru/index.xml", "layouts/_partials/comment.ru.xml") // fail } + +func TestLayoutIssue13628(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','rss','sitemap','taxonomy','term'] +-- content/p1.md -- +--- +title: p1 +layout: foo +--- +-- layouts/single.html -- +layouts/single.html +-- layouts/list.html -- +layouts/list.html +` + + for range 5 { + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/p1/index.html", "layouts/single.html") + } +} |