From 5e62cc6fce1b1b43a0c2dc585d52c2e156753372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 21 Apr 2025 11:28:33 +0200 Subject: [PATCH] tpl: Fix layout fall back logic when layout is set in front matter but not found Fixes #13630 --- tpl/tplimpl/templatedescriptor.go | 6 +---- tpl/tplimpl/templatestore_integration_test.go | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tpl/tplimpl/templatedescriptor.go b/tpl/tplimpl/templatedescriptor.go index ca73c9f78..8b50605ac 100644 --- a/tpl/tplimpl/templatedescriptor.go +++ b/tpl/tplimpl/templatedescriptor.go @@ -94,14 +94,10 @@ func (this TemplateDescriptor) doCompare(category Category, isEmbedded bool, oth } if other.LayoutFromTemplate != "" && other.LayoutFromTemplate != layoutAll { - if this.LayoutFromUser == "" { + if this.LayoutFromUser == "" || this.LayoutFromUser != other.LayoutFromTemplate { if other.LayoutFromTemplate != this.LayoutFromTemplate { return w } - } else if isLayoutStandard(this.LayoutFromUser) { - if other.LayoutFromTemplate != this.LayoutFromUser { - return w - } } } diff --git a/tpl/tplimpl/templatestore_integration_test.go b/tpl/tplimpl/templatestore_integration_test.go index 375813c31..51b28754f 100644 --- a/tpl/tplimpl/templatestore_integration_test.go +++ b/tpl/tplimpl/templatestore_integration_test.go @@ -1245,3 +1245,28 @@ p: {{ partial "p.html" . }} b.Assert(err, qt.IsNotNil) b.Assert(err.Error(), qt.Contains, "error calling partial: maximum template call stack size exceeded") } + +func TestIssue13630(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['rss','sitemap'] +-- content/p1.md -- +--- +title: p1 +layout: foo +--- +-- layouts/list.html -- +layouts/list.html +-- layouts/taxononmy.html.html -- +layouts/taxononmy.html.html +` + + var b *hugolib.IntegrationTestBuilder + + for range 3 { + b = hugolib.Test(t, files) + b.AssertFileExists("public/p1/index.html", false) + } +}