diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2025-04-14 12:00:14 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2025-04-14 14:38:22 +0200 |
commit | 65c94c7b2382a066c5a1dba49ba8a1c34a902765 (patch) | |
tree | ac426a37c9359addd9b05d4c008f88d50145742f | |
parent | e8e8ce10d2b8f2eda754639dab4d20cab9613d42 (diff) | |
download | hugo-65c94c7b2382a066c5a1dba49ba8a1c34a902765.tar.gz hugo-65c94c7b2382a066c5a1dba49ba8a1c34a902765.zip |
tpl: Fix issue with partials without suffix
Fixes #13601
-rw-r--r-- | tpl/templates/templates_integration_test.go | 20 | ||||
-rw-r--r-- | tpl/tplimpl/templatestore.go | 9 |
2 files changed, 28 insertions, 1 deletions
diff --git a/tpl/templates/templates_integration_test.go b/tpl/templates/templates_integration_test.go index 7bdcdc9f0..d16333ed4 100644 --- a/tpl/templates/templates_integration_test.go +++ b/tpl/templates/templates_integration_test.go @@ -279,3 +279,23 @@ P1. b.Assert(err, qt.IsNotNil) b.Assert(err.Error(), qt.Contains, "wrong number of args for string: want 1 got 0") } + +func TestPartialWithoutSuffixIssue13601(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +-- layouts/home.html -- +P1: {{ partial "p1" . }} +P2: {{ partial "p2" . }} +-- layouts/_partials/p1 -- +P1. +-- layouts/_partials/p2 -- +P2. +{{ return "foo bar" }} + +` + + b := hugolib.Test(t, files) + b.AssertFileContent("public/index.html", "P1: P1.\nP2: foo bar") +} diff --git a/tpl/tplimpl/templatestore.go b/tpl/tplimpl/templatestore.go index 99e8c4839..bb58c9083 100644 --- a/tpl/tplimpl/templatestore.go +++ b/tpl/tplimpl/templatestore.go @@ -913,7 +913,7 @@ func (s *TemplateStore) extractInlinePartials() error { name := templ.Name() if !paths.HasExt(name) { // Assume HTML. This in line with how the lookup works. - name = name + ".html" + name = name + s.htmlFormat.MediaType.FirstSuffix.FullSuffix } if !strings.HasPrefix(name, "_") { name = "_" + name @@ -1092,6 +1092,12 @@ func (s *TemplateStore) insertTemplate2( panic("category not set") } + if category == CategoryPartial && d.OutputFormat == "" && d.MediaType == "" { + // See issue #13601. + d.OutputFormat = s.htmlFormat.Name + d.MediaType = s.htmlFormat.MediaType.Type + } + m := tree.Get(key) nk := nodeKey{c: category, d: d} @@ -1719,6 +1725,7 @@ func (s *TemplateStore) transformTemplates() error { continue } if !vv.noBaseOf { + // TODO(bep) I don't think this branch is ever called. for vvv := range vv.BaseVariantsSeq() { tctx, err := applyTemplateTransformers(vvv.Template, lookup) if err != nil { |