{"record":{"id":"4963ccffddcf7a41","repo":"gohugoio/hugo","slug":"no-earlier-definition-of-shortcode-q-found","errorCode":null,"errorMessage":"no earlier definition of shortcode %q found","messagePattern":"no earlier definition of shortcode %q found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/shortcode.go","lineNumber":399,"sourceCode":"\n\t\t\tvar err error\n\t\t\ttmpl, err = ts.TextParse(templatePath, templStr)\n\t\t\tif err != nil {\n\t\t\t\tif isRenderString {\n\t\t\t\t\treturn zeroShortcode, p.wrapError(err)\n\t\t\t\t}\n\t\t\t\tfe := herrors.NewFileErrorFromName(err, p.File().Filename())\n\t\t\t\tpos := fe.Position()\n\t\t\t\tpos.LineNumber += p.posOffset(sc.pos).LineNumber\n\t\t\t\tfe = fe.UpdatePosition(pos)\n\t\t\t\treturn zeroShortcode, p.wrapError(fe)\n\t\t\t}\n\n\t\t} else {\n\t\t\t// Re-use of shortcode defined earlier in the same page.\n\t\t\ttmpl = ts.TextLookup(templatePath)\n\t\t\tif tmpl == nil {\n\t\t\t\treturn zeroShortcode, fmt.Errorf(\"no earlier definition of shortcode %q found\", sc.name)\n\t\t\t}\n\t\t}\n\t} else {\n\t\tofCount := map[string]int{}\n\t\tinclude := func(match *tplimpl.TemplInfo) bool {\n\t\t\tofCount[match.D.OutputFormat]++\n\t\t\treturn true\n\t\t}\n\t\tbase, layoutDescriptor := po.GetInternalTemplateBasePathAndDescriptor()\n\n\t\t// With shortcodes/mymarkdown.md (only), this allows {{% mymarkdown %}} when rendering HTML,\n\t\t// but will not resolve any template when doing {{< mymarkdown >}}.\n\t\tlayoutDescriptor.AlwaysAllowPlainText = sc.doMarkup\n\t\tq := tplimpl.TemplateQuery{\n\t\t\tPath:     base,\n\t\t\tName:     sc.name,\n\t\t\tCategory: tplimpl.CategoryShortcode,\n\t\t\tDesc:     layoutDescriptor,","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/shortcode.go#L381-L417","documentation":"Raised in doRenderShortcode (shortcode.go:399) for an inline shortcode used without a closing tag. Inline shortcodes ({{< myshort >}} without a closing {{< /myshort >}}) must reference a definition that appeared earlier in the same page; the code does ts.TextLookup on the _inline_shortcode template path and, if nil, reports no earlier definition.","triggerScenarios":"Using {{< myinline >}} (open form) before the {{< myinline >}}...{{< /myinline >}} definition that creates it; referencing an inline shortcode name that was never defined on the page; enableInlineShortcodes disabled would silently return zero, so this specifically means the lookup found nothing for a closing-less reference.","commonSituations":"Reordering content so a call appears before its inline definition; renaming an inline shortcode in one place but not the call site; copy-pasting an inline shortcode call from another page where it was defined.","solutions":["Define the inline shortcode earlier in the same page before calling its open form, or use the closing-tag form {{< name >}}body{{< /name >}} at the call site.","Ensure the call-site name exactly matches the definition name.","Consider moving the shortcode to layouts/shortcodes if it is reused across pages."],"exampleFix":"{{/* before: call before definition */}}\n{{< greeting >}}\n...\n{{< greeting >}}Hello{{< /greeting >}}\n\n{{/* after: define first */}}\n{{< greeting >}}Hello{{< /greeting >}}\n...\n{{< greeting >}}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Define inline shortcodes before their first open-form call within the same page.","Prefer the closing-tag form ({{< name >}}body{{< /name >}}) so the definition is self-contained.","Move widely-used shortcodes to layouts/shortcodes/ instead of relying on inline definitions."],"tags":["shortcode","inline-shortcode","templates"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}