{"record":{"id":"15b5abc129524e27","repo":"siyuan-note/siyuan","slug":"source-content-is-only-supported-for-template-preview","errorCode":null,"errorMessage":"Source content is only supported for template preview","messagePattern":"Source content is only supported for template preview","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/apicontract/template_render.go","lineNumber":40,"sourceCode":"\t}\n\tif r.Mode != nil {\n\t\tif *r.Mode != \"preview\" && *r.Mode != \"editorInsert\" {\n\t\t\treturn \"\", fmt.Errorf(\"Unsupported template render mode\")\n\t\t}\n\t\treturn *r.Mode, nil\n\t}\n\tif r.invalidPreview {\n\t\treturn \"\", fmt.Errorf(\"Field [preview] should be of type [Boolean]\")\n\t}\n\tif r.Preview {\n\t\treturn \"preview\", nil\n\t}\n\treturn \"content\", nil\n}\n\nfunc (r RenderTemplateRequest) PreviewSource(mode string) (*string, error) {\n\tif r.invalidContent || (r.Content != nil && mode != \"preview\") {\n\t\treturn nil, fmt.Errorf(\"Source content is only supported for template preview\")\n\t}\n\treturn r.Content, nil\n}\n\ntype TemplatePlanNode struct {\n\tID       string `json:\"id\"`\n\tTitle    string `json:\"title\"`\n\tParentID string `json:\"parentID\"`\n\tHPath    string `json:\"hPath\"`\n\tDepth    int    `json:\"depth\"`\n}\n\ntype TemplatePlan struct {\n\tID    string              `json:\"id\"`\n\tCount int                 `json:\"count\"`\n\tNodes []*TemplatePlanNode `json:\"nodes\"`\n}\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/apicontract/template_render.go#L22-L58","documentation":"The template render API only accepts a `content` (source) override when rendering in `preview` mode. PreviewSource checks that the decoded content field is valid and that the resolved mode is \"preview\"; otherwise it rejects, because supplying source content for editorInsert or content renders is not a supported combination.","triggerScenarios":"Calling the template render endpoint with both a `content` field and mode resolving to \"content\" or \"editorInsert\"; sending `content` while an invalid `preview` value previously forced a non-preview mode; passing content on the editorInsert path.","commonSituations":"Clients that always include a template source field regardless of the chosen mode; scripts written for the preview flow reused for insert flows; UI refactors that stop sending preview:true but keep sending content.","solutions":["Ensure the request resolves to preview mode (e.g. include \"preview\": true or \"mode\": \"preview\") when sending `content`","Drop the `content` field when the target mode is editorInsert or content and render the template from its stored file instead","Verify no earlier field decode error (like the preview type error) forced the mode away from preview"],"exampleFix":"// before\n{\"mode\": \"editorInsert\", \"content\": \"{{.title}}\"}\n// after\n{\"mode\": \"editorInsert\"}\n// or\n{\"preview\": true, \"content\": \"{{.title}}\"}","handlingStrategy":"validation","validationCode":"if (payload.content !== undefined && (payload.mode === \"editorInsert\" || payload.preview === false)) {\n  throw new Error(\"content is only allowed in preview mode\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only include `content` when you also request preview mode","Keep separate payload builders per mode instead of one shared body object","Document the mode/content coupling in API wrapper functions"],"tags":["validation","api","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}