siyuan-note/siyuan · error

template definition [ ] not found

Error message

template definition [%s] not found

What it means

validateTemplateCallGraph reports that a {{template "name"}} reference cannot be resolved: root.Lookup(name) returned nil, or the found template has no parse tree/root. SiYuan validates the whole call graph before executing so a missing definition fails fast with a clear message instead of a partial render.

Solutions

  1. Check the definition name in the error and correct the spelling at the call site
  2. Add the missing {{define "name"}} ... {{end}} block to the same template set
  3. If the definition lives in another file of the template package, ensure it is parsed into the same template.Template instance
  4. Use the "child template definition [%s] not found" check pattern: look up definitions before executing

Example fix

// before
{{template "heder" .}}
// after
{{template "header" .}}
Defensive patterns

Strategy: validation

Validate before calling

for _, name := range calledNames { if root.Lookup(name) == nil { return fmt.Errorf("missing definition %s", name) } }

Try / catch

if err := validateTemplateCallGraph(root, start); err != nil { return err }

Prevention

When it happens

Trigger: Raised when walking the template call graph during renderTemplateDocTreeNodeContent: a {{template "x"}} action names a definition that was never defined in the root template or in the parsed child template file.

Common situations: Typo in the template name, referencing a definition defined in another file of a template package that was not loaded, or renaming a {{define}} block without updating its call sites.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/c21fcbb42a002733. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/template_doc_tree_render.go:119

		return nil, fmt.Errorf(Conf.Language(44), err.Error())
	}
	return buf.Bytes(), nil
}

func validateTemplateCallGraph(root *template.Template, start string) error {
	visiting := map[string]bool{}
	depths := map[string]int{}
	var visit func(string) (int, error)
	visit = func(name string) (int, error) {
		if visiting[name] {
			return 0, fmt.Errorf("recursive template call [%s] is not supported", name)
		}
		if depth, ok := depths[name]; ok {
			return depth, nil
		}
		tmpl := root.Lookup(name)
		if nil == tmpl || nil == tmpl.Tree || nil == tmpl.Tree.Root {
			return 0, fmt.Errorf("template definition [%s] not found", name)
		}
		visiting[name] = true
		depth := 1
		for _, called := range collectCalledTemplateNames(tmpl.Tree.Root) {
			calledDepth, err := visit(called)
			if nil != err {
				return 0, err
			}
			if depth < calledDepth+1 {
				depth = calledDepth + 1
			}
		}
		delete(visiting, name)
		depths[name] = depth
		return depth, nil
	}
	depth, err := visit(start)
	if nil != err {

View on GitHub (pinned to 9f775e8a12)