{"record":{"id":"6f1783bf746f69a2","repo":"siyuan-note/siyuan","slug":"renderdocref-children-target-must-be-a-document-id","errorCode":null,"errorMessage":"renderDocRef children target must be a document ID","messagePattern":"renderDocRef children target must be a document ID","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":249,"sourceCode":"\nfunc (collector *templateDocTreeCollector) bindNodes(nodes []*TemplateDocTreeNode, parentID, parentPath, parentHPath string) {\n\tfor _, node := range nodes {\n\t\tnode.ParentID = parentID\n\t\tnode.path = strings.TrimSuffix(parentPath, \".sy\") + \"/\" + node.ID + \".sy\"\n\t\tnode.HPath = path.Join(parentHPath, node.Title)\n\t\tcollector.bindNodes(node.Children, node.ID, node.path, node.HPath)\n\t}\n}\n\nfunc (collector *templateDocTreeCollector) renderDocRef(mode string, value any) (any, error) {\n\tif !collector.enabled {\n\t\treturn nil, errors.New(\"renderDocRef is only available when manually inserting or previewing a template\")\n\t}\n\tswitch mode {\n\tcase \"children\":\n\t\tid, ok := value.(string)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"renderDocRef children target must be a document ID\")\n\t\t}\n\t\tif collector.rootID == id {\n\t\t\treturn collector.nodes, nil\n\t\t}\n\t\tfor _, node := range flattenTemplateDocTreeNodes0(collector.nodes) {\n\t\t\tif node.ID == id {\n\t\t\t\treturn node.Children, nil\n\t\t\t}\n\t\t}\n\t\treturn []*TemplateDocTreeNode{}, nil\n\tcase \"path\":\n\t\thPath, ok := value.(string)\n\t\tif !ok {\n\t\t\treturn \"\", errors.New(\"renderDocRef path target must be a document path\")\n\t\t}\n\t\trequestedPath := path.Clean(hPath)\n\t\tfor _, node := range flattenTemplateDocTreeNodes0(collector.nodes) {\n\t\t\trelativePath := strings.TrimPrefix(node.HPath, collector.rootHPath)","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L231-L267","documentation":"In renderDocRef mode 'children', the query value must be the document ID (a Go string) whose children should be returned. If the template passes a non-string value (number, map, nil, etc.) the collector cannot look up the target node and throws this error before any tree traversal.","triggerScenarios":"A template's renderDocRef action with mode \"children\" receives a value that is not a string — e.g. an unquoted numeric ID, a parsed template expression yielding a non-string, or a missing/nil parameter binding.","commonSituations":"Template authors forgetting to quote the ID; template engines coercing IDs that look like numbers; passing a path instead of an ID to the children mode.","solutions":["Pass the target document ID as a quoted string in the template action","Verify the template expression feeding the value evaluates to a string","Use mode \"path\" instead if you intend to target by path"],"exampleFix":"// before\n{{renderDocRef \"children\" 12345}}\n// after\n{{renderDocRef \"children\" \"20240101120000-abcdefg\"}}","handlingStrategy":"validation","validationCode":"if v, ok := value.(string); !ok || v == \"\" { return fmt.Errorf(\"children target must be a non-empty string ID\") }","typeGuard":"func isDocID(v any) bool { s, ok := v.(string); return ok && len(s) > 0 }","tryCatchPattern":"out, err := collector.renderDocRef(\"children\", value)\nif err != nil && strings.Contains(err.Error(), \"children target must be a document ID\") {\n  // coerce value to string or fix template arg\n}","preventionTips":["Always quote document IDs in template actions","Do not let template engines auto-convert numeric-looking IDs","Remember 'children' takes an ID, 'path' takes a path"],"tags":["go","template","type-error"],"backgroundTag":"type-mismatch","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"}