{"id":"7a75125cfed54f15","repo":"gohugoio/hugo","slug":"inner-cannot-be-used-inside-a-with-block-that-wrap","errorCode":null,"errorMessage":"inner cannot be used inside a with block that wraps a partial decorator","messagePattern":"inner cannot be used inside a with block that wraps a partial decorator","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/tplimpl/templatetransform.go","lineNumber":327,"sourceCode":"\t\tcase *parse.WithNode:\n\t\t\tif c.hasBreakOrContinueOutsideRange(x.List) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif c.hasBreakOrContinueOutsideRange(x.ElseList) {\n\t\t\t\treturn true\n\t\t\t}\n\t\tcase *parse.BreakNode, *parse.ContinueNode:\n\t\t\treturn true\n\n\t\t}\n\t}\n\treturn false\n}\n\nfunc (c *templateTransformContext) handleWithPartial(withNode *parse.WithNode) {\n\twithNodeInnerString := withNode.List.String()\n\tif templatesInnerRe.MatchString(withNodeInnerString) {\n\t\tc.err = fmt.Errorf(\"inner cannot be used inside a with block that wraps a partial decorator\")\n\t\treturn\n\t}\n\n\t// See #14333. That is a very odd construct, but we need to guard against it.\n\tif c.hasBreakOrContinueOutsideRange(withNode.List) {\n\t\treturn\n\t}\n\tinnerHash := hashing.XxHashFromStringHexEncoded(c.t.Name() + withNodeInnerString)\n\tinternalPartialName := fmt.Sprintf(\"_partials/%s%s\", PartialDecoratorPrefix, innerHash)\n\n\tif c.lookupFn(internalPartialName, c.t) == nil {\n\t\tinnerCopy := withNode.List.CopyList()\n\t\tti, err := c.store.addTransformedTemplateInsert(internalPartialName, SubCategoryInline)\n\t\tif err != nil {\n\t\t\tc.err = fmt.Errorf(\"failed to create internal partial decorator template %q: %w\", internalPartialName, err)\n\t\t\treturn\n\t\t}\n\t\tif ti == nil {","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/tplimpl/templatetransform.go#L309-L345","documentation":"Hugo's partial decorator feature lets a {{ with (partial ...) }} block wrap content, with {{ inner }} (matched by templatesInnerRe) providing the wrapped content. Hugo hoists the with-block body into an internal generated partial, and calling inner inside that body would recurse into the decorator machinery itself, so the transformer rejects it at build time.","triggerScenarios":"handleWithPartial finds a match for the inner keyword inside the body (List) of a with node that wraps a partial decorator call — i.e. {{ with partial \"x\" . }}...{{ inner }}...{{ end }} where the with block itself is the decorator wrapper.","commonSituations":"Authors writing shortcode-like wrapper partials confuse the decorator pattern: inner belongs inside the decorator partial's own template, not inside the with block at the call site. Often hit when refactoring nested wrapper components or copying examples incorrectly.","solutions":["Move the {{ inner }} call into the decorator partial's template file itself, not the with block body at the call site.","Restructure so the content that should be wrapped is the with block body, and the partial template uses inner to emit it.","If you need nested wrapping, nest two decorator calls rather than putting inner in the outer with body."],"exampleFix":"<!-- before: layouts/page.html -->\n{{ with partial \"card.html\" . }}\n  {{ inner }}\n{{ end }}\n\n<!-- after: layouts/page.html -->\n{{ with partial \"card.html\" . }}\n  <p>Wrapped content</p>\n{{ end }}\n<!-- layouts/_partials/card.html -->\n<div class=\"card\">{{ inner }}</div>","handlingStrategy":"validation","validationCode":"{{/* Don't do this: */}}\n{{/* {{ with .Foo }}{{ partial \"p\" . }}{{ .Inner }}{{ end }} */}}\n{{/* Instead resolve the value first, keep inner outside with */}}\n{{ $v := .Foo }}\n{{ partial \"p\" (dict \"ctx\" . \"v\" $v) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never place `.Inner` of a partial decorator inside a `with` block wrapping that partial","Hoist values into variables with `$x := ...` instead of wrapping decorator calls in with","Keep partial-decorator call sites structurally flat"],"tags":["hugo","templates","partials"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}