siyuan-note/siyuan · error

child template definition

Error message

child template definition [%s] not found

What it means

When a template doc-tree node specifies a Define (a named {{define}}/template block), the renderer looks it up in the already-parsed root template via rootTemplate.Lookup(node.Define). If no template with that name exists, rendering of the node fails with 'child template definition [%s] not found'. The name must exactly match a define declared in the same template file (or one parsed into the same *template.Template).

Solutions

  1. Verify the Define name exactly matches a {{define "..."}} block in the root template file
  2. If the define lives in another file, reference it via the node's Template field so it is parsed into the set, or include the file in the same template parse
  3. Check that the define was not swallowed by wrong delimiters — the renderer uses .action{ } delims; a define written with different syntax is ignored
  4. Search the parsed template (rootTemplate.Templates()) during development to list available define names

Example fix

// before: node references a define that does not exist
node.Define = "childSection"
// after: declare the define in the root template
// .action{define "childSection"}...content...{end}
node.Define = "childSection"
Defensive patterns

Strategy: validation

Validate before calling

for _, node := range nodes {
    if node.Define != "" && rootTemplate.Lookup(node.Define) == nil {
        return fmt.Errorf("define %q missing from root template", node.Define)
    }
}

Try / catch

err := renderTemplateDocTreeNodes(collector, rootTemplate, funcs)
if err != nil && strings.Contains(err.Error(), "not found") {
    return fmt.Errorf("check child template define names: %w", err)
}

Prevention

When it happens

Trigger: A node in the template doc tree references .action{template "name"} / Define "name" but the root template file never declares {{define "name"}} (or declares it with different casing/spelling), or the define lives in a separate file that was not parsed into the same template set.

Common situations: Typo in the Define/template name; define declared in a child template file referenced via node.Template but not included in the root set; refactoring renamed a define without updating referencing nodes; wrong delimiters causing the define to be parsed as literal text.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/template_doc_tree_render.go:73

func renderTemplateDocTreeNodeContent(collector *templateDocTreeCollector, rootTemplate *template.Template,
	funcs template.FuncMap, node *TemplateDocTreeNode) ([]byte, error) {
	if "" == node.Template && "" == node.Define {
		return nil, nil
	}

	previousAllowCreation := collector.allowCreation
	collector.allowCreation = false
	defer func() {
		collector.allowCreation = previousAllowCreation
	}()

	buf := &bytes.Buffer{}
	buf.Grow(4096)
	dataModel := templateDocTreeDataModel(node)
	if "" != node.Define {
		if nil == rootTemplate.Lookup(node.Define) {
			return nil, fmt.Errorf("child template definition [%s] not found", node.Define)
		}
		if err := validateTemplateCallGraph(rootTemplate, node.Define); nil != err {
			return nil, err
		}
		if err := rootTemplate.ExecuteTemplate(buf, node.Define, dataModel); nil != err {
			return nil, fmt.Errorf(Conf.Language(44), err.Error())
		}
		return buf.Bytes(), nil
	}

	childPath, err := resolveTemplatePackageFile(collector.templatePath, node.Template)
	if nil != err {
		return nil, err
	}
	content, err := os.ReadFile(childPath)
	if nil != err {
		return nil, err
	}

View on GitHub (pinned to 9f775e8a12)