{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/shortcode.go#L381-L417","documentation":"Inline shortcodes ({{< name.inline >}}...{{< /name.inline >}}) define their template body in the content file on first use; subsequent uses of {{< name.inline />}} without a body reuse that earlier definition, looked up under a per-page template path. If Hugo can't find a previously parsed definition with that name on the same page, it fails with this error, because there is no template body to execute.","triggerScenarios":"Using a self-closed inline shortcode ({{< foo.inline />}}) before — or without — a closed defining occurrence ({{< foo.inline >}}body{{< /foo.inline >}}) earlier in the same page. Inline shortcode definitions are scoped per page (templatePath includes p.Path()), so a definition on another page does not count.","commonSituations":"Reordering content so the self-closed reuse appears above the definition; expecting inline shortcode definitions to be shared across pages or from an archetype; copy-pasting only the reuse call; using them in .RenderString contexts without the definition.","solutions":["Add or move the full defining occurrence ({{< name.inline >}}...{{< /name.inline >}}) before any self-closed reuse on the same page.","If the logic is shared across pages, convert it to a regular shortcode file under layouts/_shortcodes/ instead of an inline shortcode.","Confirm 'security.enableInlineShortcodes = true' is set — with it off inline shortcodes render empty, but naming/order errors like this still indicate the definition is missing."],"exampleFix":"<!-- before (content/post.md) -->\n{{< greet.inline />}}\n{{< greet.inline >}}Hello {{ .Get 0 }}{{< /greet.inline >}}\n\n<!-- after -->\n{{< greet.inline >}}Hello {{ .Get 0 }}{{< /greet.inline >}}\n{{< greet.inline />}}","handlingStrategy":"validation","validationCode":"// Before overriding, confirm the shortcode exists upstream\n// e.g. check themes/<theme>/layouts/_shortcodes/<name>.html exists\nif _, err := os.Stat(filepath.Join(themeDir, \"layouts/_shortcodes\", name+\".html\")); err != nil {\n    return fmt.Errorf(\"no base shortcode %q to inherit from\", name)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only call template inheritance from a shortcode that actually overrides a theme/base shortcode of the same name","Verify the shortcode name matches the upstream file name exactly","Check the theme's layouts/_shortcodes directory before writing an override that delegates upward"],"tags":["hugo","shortcode","inline-shortcode","content"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}