]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl: Fix issue with partials without suffix
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 14 Apr 2025 10:00:14 +0000 (12:00 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 14 Apr 2025 12:38:22 +0000 (14:38 +0200)
Fixes #13601

tpl/templates/templates_integration_test.go
tpl/tplimpl/templatestore.go

index 7bdcdc9f0ae0cb2299c9b732fe1eba17c7d23a75..d16333ed43ed7c13f30df3538ee97f995a6f3386 100644 (file)
@@ -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")
+}
index 99e8c4839d1e0015b0a02be72bef8f19f146db93..bb58c90831e81c0950d5ecf303b874a1ea99c1b2 100644 (file)
@@ -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 {