{"record":{"id":"3e3558425ba5ad63","repo":"siyuan-note/siyuan","slug":"parse-template-failed-s","errorCode":null,"errorMessage":"Parse template failed: %s","messagePattern":"Parse template failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":75,"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\tabs := p\n\tif !filepath.IsAbs(abs) {\n\t\tabs = filepath.Join(util.DataDir, \"templates\", p)\n\t}","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/model/template.go#L57-L93","documentation":"RenderGoTemplateAtInBox (and its wrapper RenderGoTemplateInBox) parse user content with Go text/template using standard {{ }} delimiters; a parse failure returns i18n key 44 ('Parse template failed: %s') carrying Go's parse error text. The func map is filesys.BuiltInTemplateFuncs plus sql.SQLTemplateFuncs and a fixed 'now', so referencing any other function fails at parse time with 'function X not defined'.","triggerScenarios":"Unclosed {{, malformed pipelines, or calling a function that is not in the built-in or SQL func map inside {{...}} when rendering via RenderGoTemplate(At)InBox.","commonSituations":"Typos like {{.title}; using {{title}} without a leading dot (parsed as a function call); calling helpers that do not exist in the func map.","solutions":["Fix the syntax error at the offset quoted in Go's parse error","Reference only built-in and SQL template functions, and access data with a leading dot","Dry-run template.New(\"\").Funcs(...).Parse(content) locally before submitting"],"exampleFix":"// before\n{{title}}\n// after\n{{.title}}","handlingStrategy":"validation","validationCode":"tmpl := template.New(\"\").Funcs(filesys.BuiltInTemplateFuncs())\nif _, err := tmpl.Parse(content); err != nil {\n\treturn fmt.Errorf(\"template rejected at authoring time: %w\", err)\n}\nmodel.RenderGoTemplateInBox(content, boxID)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Dry-run template.Parse with the same func map before saving or rendering","Restrict referenced functions to the built-in and SQL template func maps"],"tags":["template","go-template","parse","sql-template"],"backgroundTag":"template-parse-error","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}