siyuan-note/siyuan · error

Source content is only supported for template preview

Error message

Source content is only supported for template preview

What it means

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.

Solutions

  1. Ensure the request resolves to preview mode (e.g. include "preview": true or "mode": "preview") when sending `content`
  2. Drop the `content` field when the target mode is editorInsert or content and render the template from its stored file instead
  3. Verify no earlier field decode error (like the preview type error) forced the mode away from preview

Example fix

// before
{"mode": "editorInsert", "content": "{{.title}}"}
// after
{"mode": "editorInsert"}
// or
{"preview": true, "content": "{{.title}}"}
Defensive patterns

Strategy: validation

Validate before calling

if (payload.content !== undefined && (payload.mode === "editorInsert" || payload.preview === false)) {
  throw new Error("content is only allowed in preview mode");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/15b5abc129524e27. Report an issue: GitHub.

Appendix: source

Thrown at kernel/apicontract/template_render.go:40

	}
	if r.Mode != nil {
		if *r.Mode != "preview" && *r.Mode != "editorInsert" {
			return "", fmt.Errorf("Unsupported template render mode")
		}
		return *r.Mode, nil
	}
	if r.invalidPreview {
		return "", fmt.Errorf("Field [preview] should be of type [Boolean]")
	}
	if r.Preview {
		return "preview", nil
	}
	return "content", nil
}

func (r RenderTemplateRequest) PreviewSource(mode string) (*string, error) {
	if r.invalidContent || (r.Content != nil && mode != "preview") {
		return nil, fmt.Errorf("Source content is only supported for template preview")
	}
	return r.Content, nil
}

type TemplatePlanNode struct {
	ID       string `json:"id"`
	Title    string `json:"title"`
	ParentID string `json:"parentID"`
	HPath    string `json:"hPath"`
	Depth    int    `json:"depth"`
}

type TemplatePlan struct {
	ID    string              `json:"id"`
	Count int                 `json:"count"`
	Nodes []*TemplatePlanNode `json:"nodes"`
}

View on GitHub (pinned to 9f775e8a12)