{"record":{"id":"cb486e9920646266","repo":"siyuan-note/siyuan","slug":"conf-language-44-err-error-template","errorCode":null,"errorMessage":"Conf.Language(44), err.Error()","messagePattern":"Conf\\.Language\\(44\\), err\\.Error\\(\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":93,"sourceCode":"\n// RenderGoTemplateAt 使用固定时间渲染 Go 模板，保证同一次业务操作中的多个模板结果一致。\nfunc RenderGoTemplateAt(templateContent string, now time.Time) (ret string, err error) {\n\treturn RenderGoTemplateAtInBox(templateContent, now, \"\")\n}\n\nfunc RenderGoTemplateInBox(templateContent, boxID string) (ret string, err error) {\n\treturn RenderGoTemplateAtInBox(templateContent, time.Now(), boxID)\n}\n\nfunc RenderGoTemplateAtInBox(templateContent string, now time.Time, boxID string) (ret string, err error) {\n\ttmpl := template.New(\"\")\n\ttplFuncMap := filesys.BuiltInTemplateFuncs()\n\ttplFuncMap[\"now\"] = func() time.Time { return now }\n\tsql.SQLTemplateFuncs(&tplFuncMap, boxID)\n\ttmpl = tmpl.Funcs(tplFuncMap)\n\ttpl, err := tmpl.Parse(templateContent)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(Conf.Language(44), err.Error())\n\t}\n\n\tbuf := &bytes.Buffer{}\n\tbuf.Grow(4096)\n\terr = tpl.Execute(buf, nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(Conf.Language(44), err.Error())\n\t}\n\tret = buf.String()\n\treturn\n}\n\n// RemoveTemplate 删除模板文件，路径必须限定在 <data>/templates/ 目录内，防止任意文件被删除\nfunc RemoveTemplate(p string) (err error) {\n\troot, rel, err := openTemplatePath(p)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template.go#L75-L111","documentation":"RenderGoTemplateAtInBox parses the document/template file content as a Go text/template and wraps any parse error with the localized message Conf.Language(44) = \"Parse template failed: %s\" plus the underlying parser error. It is thrown by the SiYuan kernel when the template text is syntactically invalid Go template syntax.","triggerScenarios":"Calling RenderGoTemplate / RenderGoTemplateAt / RenderGoTemplateInBox (or the AV new-item template resolution path) with template content containing malformed actions: unbalanced {{ }}, unknown functions, bad pipe/variable syntax in a .md template under <data>/templates/.","commonSituations":"Hand-edited template files with typos like {{ .title (missing closing braces); using a function not registered in BuiltInTemplateFuncs or sql.SQLTemplateFuncs; copying Go template snippets from another engine (Jinja/Mustache syntax); version changes where a template func was removed or renamed.","solutions":["Read the %s detail in the error — Go reports the exact line and offset of the syntax problem; fix the braces/action in the template file","Verify every function used inside {{ }} is a registered template func (e.g. now, query blocks, sql funcs); remove or replace unknown ones","Validate the template with a minimal Go text/template parse outside SiYuan to iterate quickly","If the error appeared after a SiYuan upgrade, check release notes for removed/renamed template functions"],"exampleFix":"// before (template file)\n{{ .title } and {{ now.Format \"2006\" }\n// after\n{{ .title }} and {{ now.Format \"2006\" }}","handlingStrategy":"try-catch","validationCode":"// quick client-side sanity check before calling the API\nif (!/\\{\\{[^}]*\\}\\}/.test(templateContent) && templateContent.includes(\"{\")) {\n  console.warn(\"template contains braces but no valid {{ }} action\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  const html = await fetchPost(\"/api/template/renderGoTemplate\", {id, path});\n} catch (e) {\n  if (String(e.msg).startsWith(\"Parse template failed\")) {\n    // e.msg ends with Go's line/column detail; surface it to the user for fixing the .md template\n  }\n}","preventionTips":["Never hand-edit {{ }} actions without matching braces","Only use functions documented in SiYuan template funcs (BuiltInTemplateFuncs / SQL template funcs)","Keep templates in <data>/templates/ and test with a small doc before wider use","Re-test templates after SiYuan upgrades for removed template functions"],"tags":["template","go-template","parse-error"],"backgroundTag":"template-parse-failed","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"}