{"record":{"id":"d6290d21a20ece9d","repo":"siyuan-note/siyuan","slug":"child-template-definition-s-not-found","errorCode":null,"errorMessage":"child template definition [%s] not found","messagePattern":"child template definition \\[(.+?)\\] not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree_render.go","lineNumber":73,"sourceCode":"\nfunc renderTemplateDocTreeNodeContent(collector *templateDocTreeCollector, rootTemplate *template.Template,\n\tfuncs template.FuncMap, node *TemplateDocTreeNode) ([]byte, error) {\n\tif \"\" == node.Template && \"\" == node.Define {\n\t\treturn nil, nil\n\t}\n\n\tpreviousAllowCreation := collector.allowCreation\n\tcollector.allowCreation = false\n\tdefer func() {\n\t\tcollector.allowCreation = previousAllowCreation\n\t}()\n\n\tbuf := &bytes.Buffer{}\n\tbuf.Grow(4096)\n\tdataModel := templateDocTreeDataModel(node)\n\tif \"\" != node.Define {\n\t\tif nil == rootTemplate.Lookup(node.Define) {\n\t\t\treturn nil, fmt.Errorf(\"child template definition [%s] not found\", node.Define)\n\t\t}\n\t\tif err := validateTemplateCallGraph(rootTemplate, node.Define); nil != err {\n\t\t\treturn nil, err\n\t\t}\n\t\tif err := rootTemplate.ExecuteTemplate(buf, node.Define, dataModel); nil != err {\n\t\t\treturn nil, fmt.Errorf(Conf.Language(44), err.Error())\n\t\t}\n\t\treturn buf.Bytes(), nil\n\t}\n\n\tchildPath, err := resolveTemplatePackageFile(collector.templatePath, node.Template)\n\tif nil != err {\n\t\treturn nil, err\n\t}\n\tcontent, err := os.ReadFile(childPath)\n\tif nil != err {\n\t\treturn nil, err\n\t}","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree_render.go#L55-L91","documentation":"When a template doc-tree node specifies a Define (a named {{define}}/template block), the renderer looks it up in the already-parsed root template via rootTemplate.Lookup(node.Define). If no template with that name exists, rendering of the node fails with 'child template definition [%s] not found'. The name must exactly match a define declared in the same template file (or one parsed into the same *template.Template).","triggerScenarios":"A node in the template doc tree references .action{template \"name\"} / Define \"name\" but the root template file never declares {{define \"name\"}} (or declares it with different casing/spelling), or the define lives in a separate file that was not parsed into the same template set.","commonSituations":"Typo in the Define/template name; define declared in a child template file referenced via node.Template but not included in the root set; refactoring renamed a define without updating referencing nodes; wrong delimiters causing the define to be parsed as literal text.","solutions":["Verify the Define name exactly matches a {{define \"...\"}} block in the root template file","If the define lives in another file, reference it via the node's Template field so it is parsed into the set, or include the file in the same template parse","Check that the define was not swallowed by wrong delimiters — the renderer uses .action{ } delims; a define written with different syntax is ignored","Search the parsed template (rootTemplate.Templates()) during development to list available define names"],"exampleFix":"// before: node references a define that does not exist\nnode.Define = \"childSection\"\n// after: declare the define in the root template\n// .action{define \"childSection\"}...content...{end}\nnode.Define = \"childSection\"","handlingStrategy":"validation","validationCode":"for _, node := range nodes {\n    if node.Define != \"\" && rootTemplate.Lookup(node.Define) == nil {\n        return fmt.Errorf(\"define %q missing from root template\", node.Define)\n    }\n}","typeGuard":null,"tryCatchPattern":"err := renderTemplateDocTreeNodes(collector, rootTemplate, funcs)\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n    return fmt.Errorf(\"check child template define names: %w\", err)\n}","preventionTips":["Keep define names in constants shared between nodes and template files","List available defines with rootTemplate.Templates() during development","Ensure defines use the .action{ } delimiters so they parse as templates","Update referencing nodes whenever renaming a define"],"tags":["go","template","not-found"],"backgroundTag":"resource-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"}