siyuan-note/siyuan · error

Conf.Language(44)

Error message

Conf.Language(44)

What it means

RenderGoTemplateAtInBox parses the given template content as a Go text/template with SiYuan's built-in and SQL template functions; a syntax error in Parse causes it to return the localized message Conf.Language(44) (template parse failed) wrapping the Go parser's error text. This is a template-authoring error, not a runtime/data error.

Source

Thrown at kernel/model/template.go:85

// RenderGoTemplateAt 使用固定时间渲染 Go 模板,保证同一次业务操作中的多个模板结果一致。
func RenderGoTemplateAt(templateContent string, now time.Time) (ret string, err error) {
	return RenderGoTemplateAtInBox(templateContent, now, "")
}

func RenderGoTemplateInBox(templateContent, boxID string) (ret string, err error) {
	return RenderGoTemplateAtInBox(templateContent, time.Now(), boxID)
}

func RenderGoTemplateAtInBox(templateContent string, now time.Time, boxID string) (ret string, err error) {
	tmpl := template.New("")
	tplFuncMap := filesys.BuiltInTemplateFuncs()
	tplFuncMap["now"] = func() time.Time { return now }
	sql.SQLTemplateFuncs(&tplFuncMap, boxID)
	tmpl = tmpl.Funcs(tplFuncMap)
	tpl, err := tmpl.Parse(templateContent)
	if err != nil {
		return "", fmt.Errorf(Conf.Language(44), err.Error())
	}

	buf := &bytes.Buffer{}
	buf.Grow(4096)
	err = tpl.Execute(buf, nil)
	if err != nil {
		return "", fmt.Errorf(Conf.Language(44), err.Error())
	}
	ret = buf.String()
	return
}

// RemoveTemplate 删除模板文件,路径必须限定在 <data>/templates/ 目录内,防止任意文件被删除
func RemoveTemplate(p string) (err error) {
	abs := p
	if !filepath.IsAbs(abs) {
		abs = filepath.Join(util.DataDir, "templates", p)
	}

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Read the wrapped Go parser error in the message — it names the line/offset of the syntax problem — and fix the template text accordingly
  2. Verify every {{...}} action is closed and every called function exists in SiYuan's template function set (filesys.BuiltInTemplateFuncs / sql.SQLTemplateFuncs)
  3. Test the template with a minimal RenderGoTemplate call before using it in an attribute view or document template
  4. Balance all {{if}}/{{range}}/{{with}} blocks with matching {{end}}

Example fix

// before: malformed action (missing closing braces)
templateContent := "Hello {{.title"
// after: well-formed action
templateContent := "Hello {{.title}}"
Defensive patterns

Strategy: try-catch

Validate before calling

function validateTemplateSyntax(tpl) {
  // quick structural check before sending to the kernel
  const opens = (tpl.match(/\{\{/g) || []).length;
  const closes = (tpl.match(/\}\}/g) || []).length;
  if (opens !== closes) throw new Error("unbalanced {{ }} in template");
  if (/\{\{[^}]*$/.test(tpl)) throw new Error("unclosed template action");
}

Try / catch

try {
  const html = await fetchPost("/api/template/render", { template: templateContent });
} catch (e) {
  // message wraps Conf.Language(44) with the Go parser error incl. line/column
  const parseDetail = extractParserDetail(e.message);
  showTemplateEditorError(parseDetail);
}

Prevention

When it happens

Trigger: Calling RenderGoTemplate / RenderGoTemplateAt / RenderGoTemplateInBox / RenderGoTemplateAtInBox (directly or via attribute-view item template resolution such as resolveAttributeViewNewItemTemplateWithFallback / resolveAttributeViewItemDocument) with templateContent containing invalid Go template syntax — unbalanced {{ }}, unknown functions at parse position, malformed pipelines.

Common situations: Hand-written templates with a typo like {{.Title} instead of {{.Title}}; using a function not registered in tplFuncMap or sql.SQLTemplateFuncs; templates copied from Markdown engines with different syntax (e.g. Handlebars); unclosed {{if}}/{{range}} blocks.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/cdfc7c0c32ccee0a. Report an issue: GitHub.