{"record":{"id":"7860ac8213294cbc","repo":"siyuan-note/siyuan","slug":"child-template-s-not-found-in-the-current-templ","errorCode":null,"errorMessage":"child template [%s] not found in the current template package","messagePattern":"child template \\[(.+?)\\] not found in the current template package","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":416,"sourceCode":"\trelativePath = strings.TrimPrefix(filepath.ToSlash(strings.TrimSpace(relativePath)), \"/\")\n\tcleanPath := filepath.Clean(filepath.FromSlash(relativePath))\n\tif \"\" == cleanPath || \".\" == cleanPath || filepath.IsAbs(cleanPath) || \"..\" == cleanPath ||\n\t\tstrings.HasPrefix(cleanPath, \"..\"+string(os.PathSeparator)) {\n\t\treturn \"\", errors.New(\"invalid child template path\")\n\t}\n\ttemplatesRoot := filepath.Clean(filepath.Join(util.DataDir, \"templates\"))\n\trelRootTemplate, err := filepath.Rel(templatesRoot, filepath.Clean(rootTemplatePath))\n\tif nil != err || strings.HasPrefix(relRootTemplate, \"..\"+string(os.PathSeparator)) {\n\t\treturn \"\", errors.New(\"template path is outside templates directory\")\n\t}\n\tparts := strings.Split(filepath.ToSlash(relRootTemplate), \"/\")\n\tpackageRoot := templatesRoot\n\tif 1 < len(parts) {\n\t\tpackageRoot = filepath.Join(templatesRoot, parts[0])\n\t}\n\tabsPath := filepath.Join(packageRoot, cleanPath)\n\tif !gulu.File.IsSubPath(packageRoot, absPath) || !filelock.IsExist(absPath) {\n\t\treturn \"\", fmt.Errorf(\"child template [%s] not found in the current template package\", relativePath)\n\t}\n\trealRoot, err := filepath.EvalSymlinks(packageRoot)\n\tif nil != err {\n\t\treturn \"\", err\n\t}\n\trealPath, err := filepath.EvalSymlinks(absPath)\n\tif nil != err {\n\t\treturn \"\", err\n\t}\n\tinfo, err := os.Stat(realPath)\n\tif nil != err || !info.Mode().IsRegular() {\n\t\treturn \"\", fmt.Errorf(\"child template [%s] is not a regular file\", relativePath)\n\t}\n\tif !gulu.File.IsSubPath(realRoot, realPath) {\n\t\treturn \"\", errors.New(\"child template path is outside the current template package\")\n\t}\n\treturn realPath, nil\n}","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template_doc_tree.go#L398-L434","documentation":"After computing packageRoot (the template package directory) and joining the cleaned relative path, resolveTemplatePackageFile verifies the result stays inside the package and actually exists on disk. If the joined path escapes the package or filelock.IsExist returns false, this error reports the missing child template. Note the check uses the pre-EvalSymlinks path, so a symlink pointing to a nonexistent file also lands here.","triggerScenarios":"A template references a child template path that does not exist within its package root (data/templates/<first-path-segment>), e.g. {{childTemplate \"missing.md\"}} or a typo like 'header.tpl' vs 'headers/header.tpl'; or the file was deleted/moved after the package was created.","commonSituations":"Typos in child template references; renaming or deleting part of a template package while other templates still reference it; packages copied partially (missing subdirectory); case-sensitivity mismatch on Linux after editing on Windows/macOS.","solutions":["Check the referenced child path in the template content and correct typos to match an existing file inside the package","Create the missing child template file at data/templates/<package>/<referenced-path>","Restore the deleted/renamed file (from sync history or backup) so the reference resolves","Fix filename casing to match exactly, since Linux filesystems are case-sensitive"],"exampleFix":"// before (template content)\n{{childTemplate \"Header.tpl\"}}\n// after (file on disk is header.tpl)\n{{childTemplate \"header.tpl\"}}","handlingStrategy":"validation","validationCode":"// Go: confirm each referenced child template exists inside its package before rendering\npkgRoot := filepath.Join(util.DataDir, \"templates\", pkgName)\nfor _, ref := range childRefs {\n    if _, err := os.Stat(filepath.Join(pkgRoot, filepath.FromSlash(ref))); err != nil {\n        return fmt.Errorf(\"child template %q missing in package %s\", ref, pkgName)\n    }\n}","typeGuard":null,"tryCatchPattern":"path, err := resolveTemplatePackageFile(root, rel)\nif err != nil {\n    if strings.Contains(err.Error(), \"not found in the current template package\") {\n        return fmt.Errorf(\"check reference %q — file missing or renamed\", rel)\n    }\n    return err\n}","preventionTips":["Verify child template references resolve to real files before shipping a package","Keep template packages self-contained; never delete files still referenced","Match filename casing exactly — Linux is case-sensitive","Re-check references after renaming or reorganizing a template package"],"tags":["template","file-not-found","template-package","siyuan-kernel"],"backgroundTag":"file-not-found","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}