{"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":"exception","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/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree_render.go#L101-L137","documentation":"validateTemplateCallGraph reports that a {{template \"name\"}} reference cannot be resolved: root.Lookup(name) returned nil, or the found template has no parse tree/root. SiYuan validates the whole call graph before executing so a missing definition fails fast with a clear message instead of a partial render.","triggerScenarios":"Raised when walking the template call graph during renderTemplateDocTreeNodeContent: a {{template \"x\"}} action names a definition that was never defined in the root template or in the parsed child template file.","commonSituations":"Typo in the template name, referencing a definition defined in another file of a template package that was not loaded, or renaming a {{define}} block without updating its call sites.","solutions":["Check the definition name in the error and correct the spelling at the call site","Add the missing {{define \"name\"}} ... {{end}} block to the same template set","If the definition lives in another file of the template package, ensure it is parsed into the same template.Template instance","Use the \"child template definition [%s] not found\" check pattern: look up definitions before executing"],"exampleFix":"// before\n{{template \"heder\" .}}\n// after\n{{template \"header\" .}}","handlingStrategy":"validation","validationCode":"for _, name := range calledNames { if root.Lookup(name) == nil { return fmt.Errorf(\"missing definition %s\", name) } }","typeGuard":null,"tryCatchPattern":"if err := validateTemplateCallGraph(root, start); err != nil { return err }","preventionTips":["Grep template packages for {{template \"...\"}} and confirm each name has a matching {{define}}","Rename {{define}} blocks and their call sites together","Keep all related definitions in files parsed into the same template set"],"tags":["template","missing-definition","validation"],"backgroundTag":"template-definition-not-found","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}