siyuan-note/siyuan · error
--id is required
Error message
--id is required
What it means
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`.
Source
Thrown at kernel/cli/cmd/template.go:115
fmt.Printf("[dry-run] Would remove template: %s\n", p)
return nil
}
if err := model.RemoveTemplate(abs); err != nil {
return err
}
fmt.Println("ok")
return nil
},
}
var templateRenderCmd = &cobra.Command{
Use: "render --path <path> --id <id>",
Short: "Render a template against a block (preview)",
RunE: func(cmd *cobra.Command, args []string) error {
p, _ := cmd.Flags().GetString("path")
id, _ := cmd.Flags().GetString("id")
if id == "" {
return fmt.Errorf("--id is required")
}
abs, err := resolveTemplateAbs(p)
if err != nil {
return err
}
_, dom, err := model.RenderTemplate(abs, id, true)
if err != nil {
return err
}
fmt.Print(dom)
return nil
},
}
var templateSaveAsCmd = &cobra.Command{
Use: "save-as --id <id> --name <name>",
Short: "Save a document as a template",
RunE: func(cmd *cobra.Command, args []string) error {View on GitHub (pinned to 251596fc0d)
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.
Example fix
// before siyuan template render --path daily.md // after siyuan template render --path daily.md --id 20240101000000abc123
Defensive patterns
Strategy: validation
Validate before calling
if blockID == "" {
return errors.New("--id is required: pass the block ID to render the template against")
}
// siyuan template render --path <tpl> --id <blockID> Prevention
- 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.
When it happens
Trigger: Running `siyuan template render --path foo.md` with no `--id`, or `--id ""`. Occurs when the operator provides the template but forgets the target block.
Common situations: 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.
Related errors
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/9ed7fade515c6648.
Report an issue: GitHub.