{"record":{"id":"a2ea7a4d783803a2","repo":"siyuan-note/siyuan","slug":"content-template-s-not-found","errorCode":null,"errorMessage":"content template [%s] not found","messagePattern":"content template \\[(.+?)\\] not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":1228,"sourceCode":"\t}\n\tav.BatchUpsertBlockRel(tree.Root.ChildrenByType(ast.NodeAttributeView))\n\treturn nil\n}\n\nfunc resolveDocContentTemplatePath(templatePath string) (string, error) {\n\ttemplatePath = strings.TrimPrefix(filepath.ToSlash(strings.TrimSpace(templatePath)), \"/\")\n\tcleanPath := filepath.Clean(filepath.FromSlash(templatePath))\n\tif \"\" == cleanPath || \".\" == cleanPath || filepath.IsAbs(cleanPath) || \"..\" == cleanPath ||\n\t\tstrings.HasPrefix(cleanPath, \"..\"+string(os.PathSeparator)) {\n\t\treturn \"\", errors.New(\"invalid content template path\")\n\t}\n\ttemplateRoot := filepath.Join(util.DataDir, \"templates\")\n\tabsPath := filepath.Join(templateRoot, cleanPath)\n\tif !gulu.File.IsSubPath(templateRoot, absPath) {\n\t\treturn \"\", errors.New(\"content template path is outside templates directory\")\n\t}\n\tif !filelock.IsExist(absPath) {\n\t\treturn \"\", fmt.Errorf(\"content template [%s] not found\", templatePath)\n\t}\n\trealRoot, err := filepath.EvalSymlinks(templateRoot)\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(\"content template [%s] is not a regular file\", templatePath)\n\t}\n\tif !gulu.File.IsSubPath(realRoot, realPath) {\n\t\treturn \"\", errors.New(\"content template path is outside templates directory\")\n\t}\n\treturn realPath, nil\n}","sourceCodeStart":1210,"sourceCodeEnd":1246,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template.go#L1210-L1246","documentation":"resolveDocContentTemplatePath checks that the resolved template file exists under <data>/templates/ using filelock.IsExist. When the file is missing, it reports which template path was not found. This is a plain existence check after path validation succeeded.","triggerScenarios":"Calling applyDocContentTemplate with a syntactically valid relative path (\"notes/tpl.md\") that does not exist in <data>/templates/, including wrong case on case-sensitive filesystems and typos in file extension.","commonSituations":"Template was renamed or deleted after a doc referenced it; template stored in a different notebook's assets; syncing where templates dir was excluded; typos like \"templete.md\" or missing \".md\".","solutions":["Verify the file exists at <data>/templates/<templatePath>; create it or correct the path/extension.","List available templates (e.g. via the templates API) and use an exact existing path, watching case sensitivity.","If the template was deleted, recreate it via the UI's Save as Template or the CreateTemplate API."],"exampleFix":"// before\napplyDocContentTemplate(boxID, \"meeting-note.md\", ...)\n// after\n// file exists at <data>/templates/meeting notes.md\napplyDocContentTemplate(boxID, \"meeting notes.md\", ...)","handlingStrategy":"try-catch","validationCode":"const fs = require(\"fs\");\nconst exists = fs.existsSync(process.env.SIYUAN_DATA + \"/templates/\" + templatePath);","typeGuard":null,"tryCatchPattern":"try {\n  await applyDocContentTemplate(boxID, templatePath);\n} catch (e) {\n  if (String(e).includes(\"not found\")) {\n    // list templates and prompt user to pick an existing one\n  } else { throw e; }\n}","preventionTips":["Verify the template file exists before applying it, watching for case-sensitive filesystems","Include the .md extension in template paths","Track template renames/deletions and update references that point at them"],"tags":["file-not-found","templates"],"backgroundTag":"file-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"}