Backtestshugorun-20261013-011256#15373
Support relative path calls in partials
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches take the same basic approach. They resolve `./` and `../` names against the directory of the calling partial, found via `tpl.Context.CurrentTemplate`. Both walk a `decoratorOwner` chain so that `inner` blocks in partial decorators resolve against the template that defines them. Both resolve the name before computing the `partialCached` key, so relative names from different directories do not share a cache entry.
The decisive difference is deferred templates. Deferred blocks are deduplicated by a hash of their body, plus the plain-text flag. Suppose two partials in different directories contain the same `templates.Defer` body, such as `{{ partial "./util.html" . }}`. They hash to the same deferred template. In Patch A, that template is registered once with the first owner's PathInfo, so the second partial's relative call silently resolves against the wrong directory. Patch B adds the owning partial's directory to the hash input, keeping these blocks distinct. Its `TestIncludeRelativePathInDefer` (a/main and b/main with identical defer bodies) checks exactly this case. Patch A's defer test uses only one partial, so it would not catch the bug.
Patch B is also more robust at the edges:
- It uses a checked type assertion on `CurrentTemplateInfoOps`; Patch A uses an unchecked one that could panic.
- It verifies that the partial's path actually lies under the partials container.
- It rejects a trailing slash and a name that resolves to `.`.
- Its not-found error shows both the given and resolved names.
- It skips the legacy `partials/` prefix warning for resolved names, which is tested.
- It tests the legacy `layouts/partials` directory and nested decorators.
Patch A adds documentation, which is nice but does not offset the defer-sharing correctness bug. Both test suites are meaningful, but Patch B's is broader and targets the real edge cases.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
32m 25s
Wall-clock time in the container
Full test suite
No new failures
909 passed · 28 skipped · 942 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
276vs 204 merged
Changed lines, ours vs merged
The issue
View on GitHubRight now partial calls only supports path relative to layout/partials and themes/<THEME>/layouts/partials/*<PARTIALNAME> (taken from the documentation).
This is fine when we have few partials but can become a pain if we need to organize them in subdirectories.
What i propose is to add support for relative paths like in this example :
{{ partial "./foo" ... }}
{{ partial "../bah" ... }}
Why ?
Having this feature could be beneficial in a lot or ways :
- it avoid us having to remember and write the full partial path when it's not needed (for example utility partials that are only called and only used by a on partial)
- It could allow us to reorganize partials way more easily, as relative paths would full path independent
How to implement
If the path in a partial call starts with "./" or "../", it's a relative path. Otherwise it's an "absolute" path (relative to layout/partials).
I'm against adding the current directory of the current partial to the lookup search directly though, as theme and site authors currently assume this would call to the partial root directory. Perhaps we could add this to the future, if my proposal is adopted by the community.
The two patches
tpl/partials/partials.goindex f0906fb83..72167648d 100644@@ -20,6 +20,7 @@ import ( "errors" "fmt" "html/template"+ "path" "strings" "time" @@ -111,14 +112,27 @@ func (ns *Namespace) Include(ctx context.Context, name string, contextList ...an } func (ns *Namespace) include(ctx context.Context, name string, dataList ...any) includeResult {- v, err := ns.lookup(name)+ _, v, err := ns.lookup(ctx, name) if err != nil { return includeResult{err: err} } return ns.doInclude(ctx, "", v, dataList...) } -func (ns *Namespace) lookup(name string) (*tplimpl.TemplInfo, error) {+// lookup resolves name (see resolveName) and looks up the partial.+// It returns the resolved name and the partial template.+func (ns *Namespace) lookup(ctx context.Context, name string) (string, *tplimpl.TemplInfo, error) {+ resolved, err := resolveName(ctx, name)+ if err != nil {+ return "", nil, err+ }+ if resolved != name {+ v := ns.deps.TemplateStore.LookupPartial(resolved)+ if v == nil {+ return "", nil, fmt.Errorf("partial %q (resolved to %q) not found", name, resolved)+ }+ return resolved, v, nil+ } if strings.HasPrefix(name, "partials/") { // This is most likely not what the user intended. // This worked before Hugo 0.146.0.@@ -126,9 +140,36 @@ func (ns *Namespace) lookup(name string) (*tplimpl.TemplInfo, error) { } v := ns.deps.TemplateStore.LookupPartial(name) if v == nil {- return nil, fmt.Errorf("partial %q not found", name)+ return "", nil, fmt.Errorf("partial %q not found", name)+ }+ return name, v, nil+}++// resolveName resolves a relative partial name (starting with "./" or "../")+// relative to the directory of the calling partial.+// Other names are returned unchanged.+func resolveName(ctx context.Context, name string) (string, error) {+ if !strings.HasPrefix(name, "./") && !strings.HasPrefix(name, "../") {+ return name, nil+ }+ var dir string+ var isPartial bool+ if current := tpl.Context.CurrentTemplate.Get(ctx); current != nil {+ if ti, ok := current.CurrentTemplateInfoOps.(*tplimpl.TemplInfo); ok {+ dir, isPartial = ti.PartialDir()+ } }- return v, nil+ if !isPartial {+ return "", fmt.Errorf("partial %q: relative partial names can only be used from within a partial", name)+ }+ if strings.HasSuffix(name, "/") {+ return "", fmt.Errorf("partial %q: relative partial name must not end with a slash", name)+ }+ resolved := path.Join(dir, name)+ if resolved == "." || resolved == ".." || strings.HasPrefix(resolved, "../") {+ return "", fmt.Errorf("partial %q: relative partial name resolves outside of the partials directory", name)+ }+ return resolved, nil } // include is a helper function that lookups and executes the named partial.@@ -181,6 +222,11 @@ func (ns *Namespace) doInclude(ctx context.Context, key string, templ *tplimpl.T // Note that ctx is provided by Hugo, not the end user. func (ns *Namespace) IncludeCached(ctx context.Context, name string, context any, variants ...any) (any, error) { start := time.Now()+ // Use the resolved name so relative names from different directories don't share a cache entry.+ name, ti, err := ns.lookup(ctx, name)+ if err != nil {+ return nil, err+ } keyString := name if len(variants) > 0 { key := partialCacheKey{@@ -191,10 +237,6 @@ func (ns *Namespace) IncludeCached(ctx context.Context, name string, context any } depsManagerIn := tpl.Context.GetDependencyManagerInCurrentScope(ctx)- ti, err := ns.lookup(name)- if err != nil {- return nil, err- } if parent := tpl.Context.CurrentTemplate.Get(ctx); parent != nil { for parent != nil {tpl/partials/partials_integration_test.goindex 72b5f62a5..a8c0fd75a 100644@@ -428,3 +428,187 @@ baseURL = 'http://example.com/' b.AssertFileContent("public/index.html", "42|") }++func TestIncludeRelativePath(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+baseURL = 'http://example.com/'+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS", "page"]+-- layouts/home.html --+a: {{ partial "a/b/main.html" . }}|+cached: {{ partialCached "a/main.html" . }}|{{ partialCached "a/b/main.html" . }}|+-- layouts/_partials/a/main.html --+{{- partialCached "./util.html" . -}}+-- layouts/_partials/a/util.html --+a-util+-- layouts/_partials/a/b/main.html --+{{- partial "./util.html" . }}/{{ partial "../util.html" . }}/{{ partial "./c/deep" . }}/{{ partialCached "./util.html" . -}}+-- layouts/_partials/a/b/util.html --+ab-util+-- layouts/_partials/a/b/c/deep.html --+{{- partial "../../../top.html" . -}}+-- layouts/_partials/top.html --+top+`++ b := hugolib.Test(t, files)++ b.AssertFileContent("public/index.html",+ "a: ab-util/a-util/top/ab-util|",+ "cached: a-util|ab-util/a-util/top/ab-util|",+ )+}++func TestIncludeRelativePathLegacyPartialsDir(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+baseURL = 'http://example.com/'+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS", "page"]+-- layouts/home.html --+{{ partial "a/main.html" . }}|+-- layouts/partials/a/main.html --+{{- partial "./util.html" . }}/{{ partial "../top.html" . -}}+-- layouts/partials/a/util.html --+a-util+-- layouts/partials/top.html --+top+`++ b := hugolib.Test(t, files)++ b.AssertFileContent("public/index.html", "a-util/top|")+}++func TestIncludeRelativePathInPartialDecorator(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+baseURL = 'http://example.com/'+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS", "page"]+-- layouts/home.html --+{{ partial "a/main.html" . }}|+-- layouts/_partials/a/main.html --+{{- with partial "wrap/wrapper.html" . }}{{ partial "./util.html" . }}{{ with partial "wrap/wrapper.html" . }}{{ partial "./util.html" . }}{{ end }}{{ end -}}+-- layouts/_partials/a/util.html --+a-util+-- layouts/_partials/wrap/wrapper.html --+[{{ inner . }}]+-- layouts/_partials/wrap/util.html --+wrap-util+`++ b := hugolib.Test(t, files)++ b.AssertFileContent("public/index.html", "[a-util[a-util]]|")+}++func TestIncludeRelativePathErrors(t *testing.T) {+ t.Parallel()++ filesTemplate := `+-- hugo.toml --+baseURL = 'http://example.com/'+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS", "page"]+-- layouts/home.html --+HOME+-- layouts/_partials/a/main.html --+{{ partial "../../top.html" . }}+-- layouts/_partials/top.html --+top+`++ for _, test := range []struct {+ home string+ expect string+ }{+ {`{{ partial "./top.html" . }}`, `relative partial names can only be used from within a partial`},+ {`{{ partialCached "./top.html" . }}`, `relative partial names can only be used from within a partial`},+ {`{{ partial "a/main.html" . }}`, `resolves outside of the partials directory`},+ } {+ files := strings.ReplaceAll(filesTemplate, "HOME", test.home)+ b, err := hugolib.TestE(t, files)+ b.Assert(err, qt.IsNotNil)+ b.Assert(err.Error(), qt.Contains, test.expect)+ }+}++func TestIncludeRelativePathInDefer(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+baseURL = 'http://example.com/'+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS", "page"]+-- layouts/home.html --+{{ partial "a/main.html" . }}|{{ partial "b/main.html" . }}|+-- layouts/_partials/a/main.html --+{{ with (templates.Defer (dict "key" "a")) }}{{ partial "./util.html" . }}{{ end }}+-- layouts/_partials/b/main.html --+{{ with (templates.Defer (dict "key" "b")) }}{{ partial "./util.html" . }}{{ end }}+-- layouts/_partials/a/util.html --+a-util+-- layouts/_partials/b/util.html --+b-util+`++ b := hugolib.Test(t, files)++ b.AssertFileContent("public/index.html", "a-util\n|b-util\n|")+}++func TestIncludeRelativePathNoSuperfluousPrefixWarning(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+baseURL = 'http://example.com/'+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS", "page"]+-- layouts/home.html --+{{ partial "partials/main.html" . }}+-- layouts/_partials/partials/main.html --+{{ partial "./util.html" . }}+-- layouts/_partials/partials/util.html --+util+`++ b := hugolib.Test(t, files, hugolib.TestOptWarn())++ b.AssertFileContent("public/index.html", "util")+ // The warning is only issued for names given by the user, not for resolved relative names.+ b.AssertLogContains(`partial "partials/main.html"`, `! partial "partials/util.html"`)+}++func TestIncludeRelativePathMoreErrors(t *testing.T) {+ t.Parallel()++ filesTemplate := `+-- hugo.toml --+baseURL = 'http://example.com/'+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS", "page"]+-- layouts/home.html --+{{ partial "a/main.html" . }}+-- layouts/_partials/a/main.html --+CALL+-- layouts/_partials/a.html --+a+`++ for _, test := range []struct {+ call string+ expect string+ }{+ {`{{ partial "./" . }}`, `must not end with a slash`},+ {`{{ partialCached "./" . }}`, `must not end with a slash`},+ {`{{ partial "./nope.html" . }}`, `partial "./nope.html" (resolved to "a/nope.html") not found`},+ } {+ files := strings.ReplaceAll(filesTemplate, "CALL", test.call)+ b, err := hugolib.TestE(t, files)+ b.Assert(err, qt.IsNotNil)+ b.Assert(err.Error(), qt.Contains, test.expect)+ }+}tpl/tplimpl/templatestore.goindex 4721c1f4a..1a6c1dab0 100644@@ -263,6 +263,29 @@ type TemplInfo struct { // processing state. state processingState isLegacyMapped bool++ // For internal partial decorator and deferred templates, the template that defines the block.+ decoratorOwner *TemplInfo+}++// PartialDir returns the directory of this partial template relative to the partials root,+// e.g. "foo/bar" for "layouts/_partials/foo/bar/baz.html".+// It's used to resolve relative partial names, e.g. {{ partial "./foo.html" . }}.+// For internal partial decorator and deferred templates, the template that defines the block is used.+// The second return value is false if this is not a partial template.+func (ti *TemplInfo) PartialDir() (string, bool) {+ for ti.decoratorOwner != nil {+ ti = ti.decoratorOwner+ }+ if ti.category != CategoryPartial || ti.PathInfo == nil {+ return "", false+ }+ dir := ti.PathInfo.Dir()+ prefix := "/" + containerPartials+ if dir != prefix && !strings.HasPrefix(dir, prefix+"/") {+ return "", false+ }+ return strings.TrimPrefix(strings.TrimPrefix(dir, prefix), "/"), true } func (ti *TemplInfo) SubCategory() SubCategory {@@ -943,6 +966,8 @@ func (t *TemplateStore) addDeferredTemplate(owner *TemplInfo, name string, n *pa PathInfo: owner.PathInfo, D: owner.D, Template: templ,+ // Used to resolve relative partial names in the deferred block.+ decoratorOwner: owner, }) return niltpl/tplimpl/templatetransform.goindex dcb59abe7..1b4896063 100644@@ -301,6 +301,8 @@ func (c *templateTransformContext) handleWithPartial(withNode *parse.WithNode) { c.err = fmt.Errorf("failed to find internal partial decorator template %q after insertion", internalPartialName) return }+ // Relative partial names inside the decorator block are resolved relative to the defining template.+ ti.decoratorOwner = c.t cc := newTemplateTransformContext(ti, c.store, c.lookupFn) @@ -411,7 +413,12 @@ func (c *templateTransformContext) handleWith(withNode *parse.WithNode) { // The deferred template is parsed using the owner's escaping mode. Keep // identical bodies shared within that mode, but don't let HTML and plain // text templates register the same deferred template.- innerHash := hashing.XxHashFromStringHexEncoded(fmt.Sprintf("%t:%s", c.t.D.IsPlainText, s))+ hashInput := fmt.Sprintf("%t:%s", c.t.D.IsPlainText, s)+ if dir, ok := c.t.PartialDir(); ok {+ // Relative partial names in the deferred block are resolved relative to the owning partial's directory.+ hashInput = dir + ":" + hashInput+ }+ innerHash := hashing.XxHashFromStringHexEncoded(hashInput) deferredID := tpl.HugoDeferredTemplatePrefix + innerHash c.deferNodes[deferredID] = inner
docs/content/en/functions/partials/Include.mdindex 58acbcc7f..d42dacce0 100644@@ -74,5 +74,29 @@ To return a value from a _partial_ template, it must contain only one `return` s {{ return $result }} ``` +## Relative paths++{{< new-in 0.167.0 />}}++Within a _partial_ template, a path that begins with `./` or `../` is resolved relative to the directory of the calling _partial_ template. For example, given this structure:++```tree+layouts/+└── _partials/+ ├── cards/+ │ ├── card.html+ │ └── image.html+ └── footer.html+```++The "card" _partial_ template can call its sibling and the "footer" _partial_ template like this:++```go-html-template+{{ partial "./image.html" . }}+{{ partial "../footer.html" . }}+```++Relative paths are only supported from within _partial_ templates. Calling `partial "./foo.html"` from any other template, or with a path that resolves outside the `_partials` directory, is an error.+ [`return`]: /functions/go-template/return/ [breadcrumb navigation]: /content-management/sections/#ancestors-and-descendantsdocs/content/en/functions/partials/IncludeCached.mdindex eea5751e8..a58ee53e9 100644@@ -20,6 +20,8 @@ The `partialCached` function can offer significant performance gains for complex > > Hugo renders pages in parallel, and will render the _partial_ template more than once with concurrent calls to the `partialCached` function. After Hugo caches the rendered _partial_ template, new pages entering the build pipeline will use the cached result. +Within a _partial_ template, a path that begins with `./` or `../` is resolved relative to the calling _partial_ template. See [`partials.Include`](/functions/partials/include/#relative-paths).+ Here is the simplest usage: ```go-html-templatetpl/partials/partials.goindex f0906fb83..f27ba186e 100644@@ -111,6 +111,10 @@ func (ns *Namespace) Include(ctx context.Context, name string, contextList ...an } func (ns *Namespace) include(ctx context.Context, name string, dataList ...any) includeResult {+ name, err := ns.deps.TemplateStore.ResolvePartialName(ctx, name)+ if err != nil {+ return includeResult{err: err}+ } v, err := ns.lookup(name) if err != nil { return includeResult{err: err}@@ -181,6 +185,10 @@ func (ns *Namespace) doInclude(ctx context.Context, key string, templ *tplimpl.T // Note that ctx is provided by Hugo, not the end user. func (ns *Namespace) IncludeCached(ctx context.Context, name string, context any, variants ...any) (any, error) { start := time.Now()+ name, err := ns.deps.TemplateStore.ResolvePartialName(ctx, name)+ if err != nil {+ return nil, err+ } keyString := name if len(variants) > 0 { key := partialCacheKey{tpl/partials/partials_integration_test.goindex 72b5f62a5..477eb55ee 100644@@ -428,3 +428,134 @@ baseURL = 'http://example.com/' b.AssertFileContent("public/index.html", "42|") }++// See issue 15373.+func TestIncludeRelativePath(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS"]+-- layouts/home.html --+{{ partial "a/b/main.html" . }}+{{ partial "c/main.html" . }}+{{ partial "inline.html" . }}+{{ define "_partials/a/inline.html" }}inline:{{ partial "./helper.html" . }}{{ end }}+-- layouts/_partials/inline.html --+{{ partial "a/inline.html" . }}+-- layouts/_partials/a/b/main.html --+same:{{ partial "./helper.html" . }}+sub:{{ partial "./sub/helper.html" . }}+parent:{{ partial "../helper.html" . }}+root:{{ partial "../../root.html" . }}+cached:{{ partialCached "./cached.html" . }}+dynamic:{{ partial (printf "./%s.html" "helper") . }}+include:{{ partials.Include "./helper.html" . }}+-- layouts/_partials/a/b/helper.html --+a/b/helper+-- layouts/_partials/a/b/sub/helper.html --+a/b/sub/helper+-- layouts/_partials/a/b/cached.html --+a/b/cached+-- layouts/_partials/a/helper.html --+a/helper+-- layouts/_partials/root.html --+root+-- layouts/_partials/c/main.html --+cached:{{ partialCached "./cached.html" . }}+-- layouts/_partials/c/cached.html --+c/cached+`++ b := hugolib.Test(t, files)++ b.AssertFileContent("public/index.html",+ "same:a/b/helper",+ "sub:a/b/sub/helper",+ "parent:a/helper",+ "root:root",+ "cached:a/b/cached",+ "dynamic:a/b/helper",+ "include:a/b/helper",+ "cached:c/cached",+ "inline:a/helper",+ )+}++func TestIncludeRelativePathInDecoratorInner(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS"]+-- layouts/home.html --+{{ partial "a/main.html" . }}+-- layouts/_partials/a/main.html --+{{ with partial "b/wrapper.html" . }}{{ partial "./helper.html" . }}{{ end }}+-- layouts/_partials/a/helper.html --+a/helper+-- layouts/_partials/b/wrapper.html --+wrapper:{{ inner . }}+-- layouts/_partials/b/helper.html --+b/helper+`++ b := hugolib.Test(t, files)++ b.AssertFileContent("public/index.html", "wrapper:a/helper")+}++func TestIncludeRelativePathNotFromPartial(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS"]+-- layouts/home.html --+{{ partial "./helper.html" . }}+-- layouts/_partials/helper.html --+helper+`++ b, err := hugolib.TestE(t, files)++ b.Assert(err, qt.ErrorMatches, `(?s).*relative partial path "./helper.html" can only be used from within a partial.*`)+}++func TestIncludeRelativePathOutsidePartials(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS"]+-- layouts/home.html --+{{ partial "a/main.html" . }}+-- layouts/_partials/a/main.html --+{{ partial "../../helper.html" . }}+-- layouts/_partials/helper.html --+helper+`++ b, err := hugolib.TestE(t, files)++ b.Assert(err, qt.ErrorMatches, `(?s).*relative partial path "../../helper.html" in "_partials/a/main.html" resolves outside the partials directory.*`)+}++func TestIncludeRelativePathInDeferredBlock(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+disableKinds = ["section", "taxonomy", "term", "sitemap", "RSS"]+-- layouts/home.html --+{{ partial "a/main.html" . }}+-- layouts/_partials/a/main.html --+{{ with (templates.Defer (dict "key" "a")) }}deferred:{{ partial "./helper.html" . }}{{ end }}+-- layouts/_partials/a/helper.html --+a/helper+`++ b := hugolib.Test(t, files)++ b.AssertFileContent("public/index.html", "deferred:a/helper")+}tpl/tplimpl/templatestore.goindex 4721c1f4a..b1aed169f 100644@@ -249,6 +249,9 @@ type TemplInfo struct { // The base template used, if any. base *TemplInfo + // For partial decorator inner templates, the template the inner block was defined in.+ decoratorOwner *TemplInfo+ // The descriptior that this template represents. D TemplateDescriptor @@ -636,6 +639,31 @@ func (s *TemplateStore) LookupPartial(pth string) *TemplInfo { return ti } +// ResolvePartialName resolves partial names starting with "./" or "../"+// relative to the directory of the calling partial.+func (s *TemplateStore) ResolvePartialName(ctx context.Context, name string) (string, error) {+ if !strings.HasPrefix(name, "./") && !strings.HasPrefix(name, "../") {+ return name, nil+ }+ cur := tpl.Context.CurrentTemplate.Get(ctx)+ if cur == nil {+ return "", fmt.Errorf("relative partial path %q can only be used from within a partial", name)+ }+ ti := cur.CurrentTemplateInfoOps.(*TemplInfo)+ for ti.decoratorOwner != nil {+ ti = ti.decoratorOwner+ }+ if ti.category != CategoryPartial {+ return "", fmt.Errorf("relative partial path %q can only be used from within a partial, called from %q", name, ti.Name())+ }+ dir := strings.TrimPrefix(strings.TrimPrefix(ti.PathInfo.Dir(), "/"+containerPartials), "/")+ resolved := path.Join(dir, name)+ if resolved == ".." || strings.HasPrefix(resolved, "../") {+ return "", fmt.Errorf("relative partial path %q in %q resolves outside the partials directory", name, ti.Name())+ }+ return resolved, nil+}+ func (s *TemplateStore) LookupShortcodeByName(name string) *TemplInfo { name = strings.ToLower(name) ti, _ := s.shortcodesByName.Get(name)@@ -939,10 +967,12 @@ func (t *TemplateStore) addDeferredTemplate(owner *TemplInfo, name string, n *pa } t.templatesByPath.Set(name, &TemplInfo{- Fi: owner.Fi,- PathInfo: owner.PathInfo,- D: owner.D,- Template: templ,+ Fi: owner.Fi,+ PathInfo: owner.PathInfo,+ D: owner.D,+ Template: templ,+ category: owner.category,+ decoratorOwner: owner.decoratorOwner, }) return niltpl/tplimpl/templatetransform.goindex dcb59abe7..3c37ea6ef 100644@@ -301,6 +301,7 @@ func (c *templateTransformContext) handleWithPartial(withNode *parse.WithNode) { c.err = fmt.Errorf("failed to find internal partial decorator template %q after insertion", internalPartialName) return }+ ti.decoratorOwner = c.t cc := newTemplateTransformContext(ti, c.store, c.lookupFn)