Skip to content

Commit 1e0287f

Browse files
committed
tpl: Make {{ template "partials/foo.html" . }} work in older setups
Fixes #13599
1 parent 915ba3f commit 1e0287f

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

Diff for: tpl/templates/templates_integration_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 The Hugo Authors. All rights reserved.
1+
// Copyright 2025 The Hugo Authors. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

Diff for: tpl/tplimpl/legacy_integration_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2025 The Hugo Authors. All rights reserved.
2+
//
3+
// Portions Copyright The Go Authors.
4+
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package tplimpl_test
17+
18+
import (
19+
"testing"
20+
21+
"github.com/gohugoio/hugo/hugolib"
22+
)
23+
24+
func TestLegacyPartialIssue13599(t *testing.T) {
25+
t.Parallel()
26+
27+
files := `
28+
-- hugo.toml --
29+
-- layouts/partials/mypartial.html --
30+
Mypartial.
31+
-- layouts/_default/index.html --
32+
mypartial: {{ template "partials/mypartial.html" . }}
33+
34+
`
35+
b := hugolib.Test(t, files)
36+
37+
b.AssertFileContent("public/index.html", "Mypartial.")
38+
}

Diff for: tpl/tplimpl/templates.go

+7
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@ func (t *templateNamespace) parseTemplate(ti *TemplInfo) error {
9999
return err
100100
}
101101
}
102+
}
102103

104+
// Issue #13599.
105+
if ti.category == CategoryPartial && ti.Fi != nil && ti.Fi.Meta().PathInfo.Section() == "partials" {
106+
aliasName := strings.TrimPrefix(name, "_")
107+
if _, err := prototype.AddParseTree(aliasName, templ.(*htmltemplate.Template).Tree); err != nil {
108+
return err
109+
}
103110
}
104111
}
105112

Diff for: tpl/tplimpl/templatestore.go

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Copyright 2025 The Hugo Authors. All rights reserved.
2+
//
3+
// Portions Copyright The Go Authors.
4+
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
116
package tplimpl
217

318
import (

Diff for: tpl/tplimpl/tplimpl_integration_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Copyright 2025 The Hugo Authors. All rights reserved.
2+
//
3+
// Portions Copyright The Go Authors.
4+
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
116
package tplimpl_test
217

318
import (

0 commit comments

Comments
 (0)