{"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":127,"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":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/template.go#L109-L145","documentation":"`siyuan template render` renders a template against an existing block identified by `--id`; the id is mandatory because RenderTemplate needs the target block to bind template variables. The command returns this error when the flag is missing or empty.","triggerScenarios":"Running `siyuan template render --path tpl.md` without `--id <block-id>`.","commonSituations":"Having a valid --path but forgetting the block id; using an id copied with trailing whitespace that got trimmed to empty; scripting where the id lookup failed upstream.","solutions":["Pass the block id: `siyuan template render --path tpl.md --id 20240101120000-abcdefg`","Copy the block id from SiYuan (block context menu > copy block ID) and verify it is non-empty","Check the preceding command that produces the id variable actually succeeded"],"exampleFix":"// before\nsiyuan template render --path tpl.md\n// after\nsiyuan template render --path tpl.md --id 20240101120000-abcdefg","handlingStrategy":"validation","validationCode":"if [ -z \"$BLOCK_ID\" ]; then echo \"--id is required\" >&2; exit 2; fi\nsiyuan template render --path tpl.md --id \"$BLOCK_ID\"","typeGuard":null,"tryCatchPattern":"if ! siyuan template render --path tpl.md --id \"$ID\"; then\n  echo \"render failed; verify block id and path\" >&2\nfi","preventionTips":["Copy block IDs from the SiYuan UI and store them trimmed","Check the upstream command that yields the id succeeded","Always pass --id together with --path"],"tags":["cli","template","missing-flag"],"backgroundTag":"missing-required-flag","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"}