{"record":{"id":"c21fcbb42a002733","repo":"siyuan-note/siyuan","slug":"template-definition-s-not-found","errorCode":null,"errorMessage":"template definition [%s] not found","messagePattern":"template definition \\[(.+?)\\] not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree_render.go","lineNumber":119,"sourceCode":"\t\treturn nil, fmt.Errorf(Conf.Language(44), err.Error())\n\t}\n\treturn buf.Bytes(), nil\n}\n\nfunc validateTemplateCallGraph(root *template.Template, start string) error {\n\tvisiting := map[string]bool{}\n\tdepths := map[string]int{}\n\tvar visit func(string) (int, error)\n\tvisit = func(name string) (int, error) {\n\t\tif visiting[name] {\n\t\t\treturn 0, fmt.Errorf(\"recursive template call [%s] is not supported\", name)\n\t\t}\n\t\tif depth, ok := depths[name]; ok {\n\t\t\treturn depth, nil\n\t\t}\n\t\ttmpl := root.Lookup(name)\n\t\tif nil == tmpl || nil == tmpl.Tree || nil == tmpl.Tree.Root {\n\t\t\treturn 0, fmt.Errorf(\"template definition [%s] not found\", name)\n\t\t}\n\t\tvisiting[name] = true\n\t\tdepth := 1\n\t\tfor _, called := range collectCalledTemplateNames(tmpl.Tree.Root) {\n\t\t\tcalledDepth, err := visit(called)\n\t\t\tif nil != err {\n\t\t\t\treturn 0, err\n\t\t\t}\n\t\t\tif depth < calledDepth+1 {\n\t\t\t\tdepth = calledDepth + 1\n\t\t\t}\n\t\t}\n\t\tdelete(visiting, name)\n\t\tdepths[name] = depth\n\t\treturn depth, nil\n\t}\n\tdepth, err := visit(start)\n\tif nil != err {","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template_doc_tree_render.go#L101-L137","documentation":"During the static call-graph walk, every referenced template name is resolved with root.Lookup. If a {{template \"name\"}} action references a define that does not exist in the template set (or has an empty AST), the walk fails with 'template definition [%s] not found'. This is essentially the same family as error 1543 but detected during call-graph validation rather than direct node rendering.","triggerScenarios":"A define or child template file contains {{template \"missingName\"}} (or .action{template \"missingName\"}) where missingName was never defined via {{define}} in the same template set; an empty define block with no root node also triggers it.","commonSituations":"Typo in a template include name; include copied from another template package whose defines weren't loaded; conditional includes of names defined only in files that failed to load; renaming a define without updating callers.","solutions":["Define the missing template with {{define \"name\"}}...{{end}} in the same template set","Fix the include name to match an existing define exactly (spelling/case)","Ensure all files providing referenced defines are parsed into the same template set before validation","Remove the stale {{template}} call if the referenced define is no longer needed"],"exampleFix":"// before\n.action{template \"header-v2\"}\n// after (define exists as \"header\")\n.action{template \"header\"}","handlingStrategy":"validation","validationCode":"for _, name := range referencedTemplateNames(tmplFiles) {\n\tif tmplSet.Lookup(name) == nil {\n\t\treturn fmt.Errorf(\"referenced define %q missing from template set\", name)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep define names in one place and reference them via constants","Parse all files of a template package into one template set before validating includes","Grep for {{template \"...\"}} references and verify each has a matching define in CI"],"tags":["go","template","not-found","include"],"backgroundTag":"resource-not-found","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}