{"id":"d6b90d78be93b8a5","repo":"gohugoio/hugo","slug":"renderstring-unknown-shortcode-token-q","errorCode":null,"errorMessage":"RenderString: unknown shortcode token %q","messagePattern":"RenderString: unknown shortcode token %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/page__content.go","lineNumber":1005,"sourceCode":"\t\t\t\tif token == tocShortcodePlaceholder {\n\t\t\t\t\ttoc, err := c.contentToC(ctx)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\t\t\t\t\t// The Page's TableOfContents was accessed in a shortcode.\n\t\t\t\t\treturn []byte(toc.tableOfContentsHTML), nil\n\t\t\t\t}\n\t\t\t\trenderer, found := placeholders[token]\n\t\t\t\tif found {\n\t\t\t\t\trepl, more, err := renderer.renderShortcode(ctx)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\t\t\t\t\thasShortcodeVariants = hasShortcodeVariants || more\n\t\t\t\t\treturn repl, nil\n\t\t\t\t}\n\t\t\t\t// This should not happen.\n\t\t\t\treturn nil, fmt.Errorf(\"RenderString: unknown shortcode token %q\", token)\n\t\t\t}\n\n\t\t\trendered, err = expandShortcodeTokens(ctx, rendered, tokenHandler)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\tif hasShortcodeVariants {\n\t\t\t\tpco.po.p.incrPageOutputTemplateVariation()\n\t\t\t}\n\t\t}\n\n\t\t// We need a consolidated view in $page.HasShortcode\n\t\tcombined := pco.po.p.m.content.hasShortcode.Load().Or(parseInfo.shortcodeParseInfo.hasName)\n\t\tpco.po.p.m.content.hasShortcode.Store(&combined)\n\n\t} else {\n\t\tsi := sourceInfo{\n\t\t\tfilename: pco.po.p.pathOrTitle() + \" (rendered from string)\",","sourceCodeStart":987,"sourceCodeEnd":1023,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/page__content.go#L987-L1023","documentation":"The RenderString-path analog of the placeholder-lookup failure: when RenderString renders text containing shortcodes, each shortcode is replaced by a placeholder token and later expanded; if a token in the rendered output has no matching renderer in the placeholder map (and isn't the TOC placeholder), this error is returned. The code marks it \"should not happen\" — an internal bookkeeping invariant broke, though unlike the page-content path it returns an error instead of panicking.","triggerScenarios":"Calling `.RenderString` on a string containing `{{< shortcode >}}` markup where the token map built during parsing doesn't cover a token found post-render — e.g. input text that literally contains a Hugo placeholder marker, or the rendered markdown mangling/duplicating a token so it no longer matches.","commonSituations":"Passing content that already went through Hugo's pipeline (containing leftover placeholder strings) into RenderString; markdown processing that splits a placeholder across elements in unusual markup configurations; genuine Hugo regressions after upgrades.","solutions":["Check the string you pass to RenderString for a literal internal placeholder pattern (HAHAHUGOSHORTCODE...) — strip or avoid feeding pipeline output back in; render from the raw source instead.","Restart `hugo server` / clear caches to eliminate stale placeholder state.","Reduce to a minimal reproduction; if it reproduces on a clean build with plain input, file a bug at github.com/gohugoio/hugo including the input string and shortcodes involved."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"{{/* ensure any shortcode named inside the RenderString input exists in layouts/_shortcodes/ */}}\n{{ $out := .RenderString \"{{</* myshortcode */>}}\" }}","typeGuard":null,"tryCatchPattern":"if err := h.Build(cfg); err != nil && strings.Contains(err.Error(), \"RenderString: unknown shortcode token\") {\n    // shortcode used in RenderString input isn't resolvable in that context\n    return err\n}","preventionTips":["Verify shortcodes referenced in RenderString input exist and are spelled correctly","Avoid shortcodes that depend on page context when rendering detached strings","Cover RenderString-with-shortcode paths in hugolib.Test integration tests"],"tags":["hugo","renderstring","shortcode","internal-state"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}