{"record":{"id":"401b0459676b1e0c","repo":"siyuan-note/siyuan","slug":"use-template-for-a-template-field","errorCode":null,"errorMessage":"use template for a template field","messagePattern":"use template for a template field","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_key_config.go","lineNumber":80,"sourceCode":"\t\t\tcase \"icon\":\n\t\t\t\treturn setAttributeViewColIcon(op)\n\t\t\tcase \"desc\":\n\t\t\t\treturn setAttributeViewColDesc(op)\n\t\t\tcase \"numberFormat\":\n\t\t\t\tif av.KeyTypeNumber != key.Type || !slices.Contains(AttributeViewKeyNumberFormats, text) {\n\t\t\t\t\treturn errors.New(\"numberFormat requires a number field and a supported format\")\n\t\t\t\t}\n\t\t\t\treturn updateAttributeViewColNumberFormat(op)\n\t\t\tcase \"dateFormat\":\n\t\t\t\treturn setAttributeViewColDateFormat(op)\n\t\t\tcase \"template\":\n\t\t\t\tif av.KeyTypeTemplate != key.Type {\n\t\t\t\t\treturn errors.New(\"template requires a template field; use renderTemplate for other fields\")\n\t\t\t\t}\n\t\t\t\treturn updateAttributeViewColTemplate(op)\n\t\t\tcase \"renderTemplate\":\n\t\t\t\tif av.KeyTypeTemplate == key.Type {\n\t\t\t\t\treturn errors.New(\"use template for a template field\")\n\t\t\t\t}\n\t\t\t\treturn updateAttributeViewColTemplate(op)\n\t\t\t}\n\t\tcase \"autoFillNow\", \"fillSpecificTime\", \"includeTime\":\n\t\t\tflag, ok := value.(bool)\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"%s must be a boolean\", setting)\n\t\t\t}\n\t\t\top.Data = flag\n\t\t\tif \"includeTime\" == setting {\n\t\t\t\tswitch key.Type {\n\t\t\t\tcase av.KeyTypeCreated:\n\t\t\t\t\treturn setAttrViewCreatedIncludeTime(op)\n\t\t\t\tcase av.KeyTypeUpdated:\n\t\t\t\t\treturn setAttrViewUpdatedIncludeTime(op)\n\t\t\t\t}\n\t\t\t\treturn errors.New(\"includeTime requires a created or updated field\")\n\t\t\t}","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_key_config.go#L62-L98","documentation":"UpdateAttributeViewKeyConfig routes each one-key config map to a handler based on the setting name. The 'renderTemplate' setting evaluates a template against a row for non-template fields, while 'template' changes the template expression of a template-typed field. When the target field is already of type 'template', 'renderTemplate' is rejected because it is the wrong setter for that field type.","triggerScenarios":"Calling UpdateAttributeViewKeyConfig(avID, keyID, {\"renderTemplate\": \"...\"}) where key.Type == av.KeyTypeTemplate (the field was created as a template field).","commonSituations":"A client script or plugin updates field configs generically and applies renderTemplate to every field it touches, including template fields; or the field's type was switched to template earlier and the caller's cached field-type info is stale.","solutions":["Use the 'template' setting instead of 'renderTemplate' for this field: {\"template\": \"<expression>\"}.","Check the field's type first (via the attribute view API) and pick 'template' for template fields, 'renderTemplate' for others.","If the field should not be a template field, change its type via the 'type' setting before using renderTemplate."],"exampleFix":"// before\nUpdateAttributeViewKeyConfig(avID, keyID, {\"renderTemplate\": \"=this.price*1.1\"})\n// after\nUpdateAttributeViewKeyConfig(avID, keyID, {\"template\": \"=this.price*1.1\"})","handlingStrategy":"validation","validationCode":"// JS: check field type before choosing the setting\nif (key.type === \"template\") {\n  config = { template: expr };\n} else {\n  config = { renderTemplate: expr };\n}","typeGuard":"function isTemplateField(key) { return key && key.type === \"template\"; }","tryCatchPattern":"try { await updateKeyConfig(avID, keyID, cfg); } catch (e) { if (String(e).includes(\"use template for a template field\")) { await updateKeyConfig(avID, keyID, { template: cfg.renderTemplate }); } else { throw e; } }","preventionTips":["Fetch the field's type before selecting template vs renderTemplate","Centralize the setting-name choice in one helper keyed by field type","Refresh cached field metadata after any 'type' change"],"tags":["attribute-view","validation","wrong-setting"],"backgroundTag":"invalid-argument-value","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"}