{"record":{"id":"9ed7fade515c6648","repo":"siyuan-note/siyuan","slug":"id-is-required-9ed7fa","errorCode":null,"errorMessage":"--id is required","messagePattern":"--id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/template.go","lineNumber":115,"sourceCode":"\t\t\tfmt.Printf(\"[dry-run] Would remove template: %s\\n\", p)\n\t\t\treturn nil\n\t\t}\n\t\tif err := model.RemoveTemplate(abs); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfmt.Println(\"ok\")\n\t\treturn nil\n\t},\n}\n\nvar templateRenderCmd = &cobra.Command{\n\tUse:   \"render --path <path> --id <id>\",\n\tShort: \"Render a template against a block (preview)\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tp, _ := cmd.Flags().GetString(\"path\")\n\t\tid, _ := cmd.Flags().GetString(\"id\")\n\t\tif id == \"\" {\n\t\t\treturn fmt.Errorf(\"--id is required\")\n\t\t}\n\t\tabs, err := resolveTemplateAbs(p)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\t_, dom, err := model.RenderTemplate(abs, id, true)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfmt.Print(dom)\n\t\treturn nil\n\t},\n}\n\nvar templateSaveAsCmd = &cobra.Command{\n\tUse:   \"save-as --id <id> --name <name>\",\n\tShort: \"Save a document as a template\",\n\tRunE: func(cmd *cobra.Command, args []string) error {","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/template.go#L97-L133","documentation":"Thrown by the `template render` cobra subcommand when `--id` is empty. `--id` is the block ID the template is rendered against (via `model.RenderTemplate(abs, id, true)`), used to resolve block attributes/variables inside the template. The check runs before template-path resolution so a missing block ID fails fast. Note `--path` (the template file) is validated separately by `resolveTemplateAbs`.","triggerScenarios":"Running `siyuan template render --path foo.md` with no `--id`, or `--id \"\"`. Occurs when the operator provides the template but forgets the target block.","commonSituations":"Assuming render uses the currently-selected block (CLI is stateless — there is none); confusing `--id` (block) with the template `--path`; scripting render and omitting the block ID.","solutions":["Pass a block ID: `siyuan template render --path <tpl> --id <blockID>`.","Obtain the block ID from `siyuan block --id <doc> tree` or the editor's block-ID display."],"exampleFix":"// before\nsiyuan template render --path daily.md\n// after\nsiyuan template render --path daily.md --id 20240101000000abc123","handlingStrategy":"validation","validationCode":"if blockID == \"\" {\n    return errors.New(\"--id is required: pass the block ID to render the template against\")\n}\n// siyuan template render --path <tpl> --id <blockID>","typeGuard":null,"tryCatchPattern":null,"preventionTips":["The CLI is stateless — there is no 'current block'; always pass `--id`.","Distinguish `--id` (block) from `--path` (template file).","Obtain block IDs via `block tree` or the editor."],"tags":["cli","validation","template","block","argument-required"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}