{"id":"b9381a041ea114ca","repo":"gohugoio/hugo","slug":"failed-to-render-shortcode-w","errorCode":null,"errorMessage":"failed to render shortcode: %w","messagePattern":"failed to render shortcode: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/page__content.go","lineNumber":249,"sourceCode":"\t\tcase pageparser.Item:\n\t\t\tsm = append(sm, sourceMapEntry{renderOffset: len(c), sourceOffset: v.Pos()})\n\t\t\tc = append(c, source[v.Pos():v.Pos()+len(v.Val(source))]...)\n\t\tcase pageContentReplacement:\n\t\t\tsm = append(sm, sourceMapEntry{renderOffset: len(c), sourceOffset: v.source.Pos()})\n\t\t\tc = append(c, v.val...)\n\t\tcase *shortcode:\n\t\t\tsm = append(sm, sourceMapEntry{renderOffset: len(c), sourceOffset: v.pos, isShortcode: true})\n\t\t\tif !v.insertPlaceholder() {\n\t\t\t\t// Insert the rendered shortcode.\n\t\t\t\trenderedShortcode, found := renderedShortcodes[v.placeholder]\n\t\t\t\tif !found {\n\t\t\t\t\t// This should never happen.\n\t\t\t\t\tpanic(fmt.Sprintf(\"rendered shortcode %q not found\", v.placeholder))\n\t\t\t\t}\n\n\t\t\t\tb, more, err := renderedShortcode.renderShortcode(ctx)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, nil, false, fmt.Errorf(\"failed to render shortcode: %w\", err)\n\t\t\t\t}\n\t\t\t\thasVariants = hasVariants || more\n\t\t\t\tc = append(c, []byte(b)...)\n\n\t\t\t} else {\n\t\t\t\t// Insert the placeholder so we can insert the content after\n\t\t\t\t// markdown processing.\n\t\t\t\tc = append(c, []byte(v.placeholder)...)\n\t\t\t}\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"unknown item type %T\", it))\n\t\t}\n\t}\n\n\treturn c, sm, hasVariants, nil\n}\n\nfunc (c *cachedContent) IsZero() bool {","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/page__content.go#L231-L267","documentation":"Emitted from contentParseInfo.contentToRender in hugolib/page__content.go when a shortcode that was pre-rendered for a page fails as its output is inlined into the content stream before Goldmark processing. The shortcode's template executed with an error, and Hugo wraps that error to abort rendering of the page.","triggerScenarios":"Building a site where a page contains a `{{< shortcode >}}` whose template errors at render time: undefined method on .Params, failing resources.Get/GetRemote inside the shortcode, `errorf` called in the shortcode template, or a nested inner shortcode failing.","commonSituations":"Theme shortcodes that expect parameters the content author omitted; shortcodes fetching remote resources that 404 or time out; Hugo version upgrades removing template functions a shortcode used; shortcodes referencing page resources that don't exist in the bundle.","solutions":["Inspect the wrapped error — it includes the shortcode name, file, and line of the failing template action.","Fix the shortcode call in the content file (add missing named/positional params) or harden the shortcode template with `{{ with ... }}` guards.","If it's a theme shortcode, override it in layouts/_shortcodes/ (or layouts/shortcodes/ in older versions) with a corrected copy.","Run `hugo --logLevel debug` to see which page and shortcode invocation triggers it."],"exampleFix":"{{/* layouts/_shortcodes/img.html before */}}\n<img src=\"{{ (.Page.Resources.Get (.Get 0)).RelPermalink }}\">\n{{/* after */}}\n{{ with .Page.Resources.Get (.Get 0) }}<img src=\"{{ .RelPermalink }}\">{{ else }}{{ errorf \"img shortcode: resource %q not found in %s\" (.Get 0) .Page.File.Path }}{{ end }}","handlingStrategy":"try-catch","validationCode":"// confirm the shortcode template exists before authoring content that uses it\n// ls layouts/_shortcodes/myshortcode.html","typeGuard":null,"tryCatchPattern":"content, err := p.Content(ctx)\nif err != nil {\n    // error already wraps file position of the failing shortcode\n    return fmt.Errorf(\"page %s: %w\", p.Path(), err)\n}","preventionTips":["Write hugolib integration tests that render every custom shortcode","Validate .Get parameters inside shortcode templates with errorf/warnf","Never call methods on possibly-nil values in shortcodes; use `with`","Run a full `hugo` build in CI so shortcode failures fail the pipeline"],"tags":["hugo","shortcode","rendering","templates"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}