{"record":{"id":"72e8a79e5dfe84e1","repo":"siyuan-note/siyuan","slug":"new-item-template-s-not-found","errorCode":null,"errorMessage":"new item template [%s] not found","messagePattern":"new item template \\[(.+?)\\] not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_new_item.go","lineNumber":104,"sourceCode":"func CreateAttributeViewItemWithMarkdown(avID, blockID, viewID, templateID, previousID, groupID string,\n\tdocument *CreateAttributeViewItemMarkdown) (*CreateAttributeViewItemResult, error) {\n\tif nil == document {\n\t\treturn nil, errors.New(\"attribute view item markdown is nil\")\n\t}\n\treturn createAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID, document)\n}\n\nfunc createAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID string,\n\tdocument *CreateAttributeViewItemMarkdown) (*CreateAttributeViewItemResult, error) {\n\tattrView, err := avParseView(avID, blockID)\n\tif nil != err {\n\t\treturn nil, err\n\t}\n\tcreatedAt := time.Now()\n\titemTemplate := attrView.GetNewItemTemplate(templateID)\n\tvar prunedOptions []*av.PrunedNewItemTemplateOption\n\tif \"\" != templateID && nil == itemTemplate {\n\t\treturn nil, fmt.Errorf(\"new item template [%s] not found\", templateID)\n\t}\n\tif nil == itemTemplate {\n\t\titemTemplate = &av.NewItemTemplate{TargetType: av.NewItemTargetDetached}\n\t} else {\n\t\tcloned := *attrView\n\t\tprunedOptions = cloned.PruneInvalidNewItemTemplateFieldValues()\n\t\tif err = cloned.SetNewItemTemplates(&av.NewItemTemplatesConfig{Templates: []*av.NewItemTemplate{itemTemplate}}); nil != err {\n\t\t\treturn nil, err\n\t\t}\n\t\tattrView = &cloned\n\t\titemTemplate = cloned.NewItemTemplates[0]\n\t}\n\tif nil != document && av.NewItemTargetDocument != itemTemplate.TargetType {\n\t\treturn nil, fmt.Errorf(\"new item template [%s] does not create a bound block\", templateID)\n\t}\n\tprimaryFallback := \"\"\n\tif nil != document {\n\t\tprimaryFallback = document.Title","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_new_item.go#L86-L122","documentation":"createAttributeViewItem resolves an optional templateID against the attribute view's registered new-item templates. If a non-empty templateID is supplied but no template with that ID exists, the creation is aborted with this formatted error naming the missing template ID.","triggerScenarios":"Calling CreateAttributeViewItem or CreateAttributeViewItemWithMarkdown with a templateID that is not registered in the attribute view's new-item templates (empty templateID is allowed and falls back to the detached default).","commonSituations":"Stale template IDs after a template was deleted or the view was reconfigured; template IDs copied from another attribute view; plugin clients caching template IDs across view edits.","solutions":["Fetch the attribute view's new-item templates (e.g. GetNewItemTemplate options) and use a valid templateID","Omit templateID (empty string) to create a default detached item","Re-list templates at call time instead of using a cached ID"],"exampleFix":"// before\nres, err := CreateAttributeViewItem(avID, blockID, viewID, \"tpl-gone\", prevID, groupID)\n// after\ntplID := \"\"\nif attrView.GetNewItemTemplate(\"tpl-gone\") != nil {\n    tplID = \"tpl-gone\"\n}\nres, err := CreateAttributeViewItem(avID, blockID, viewID, tplID, prevID, groupID)","handlingStrategy":"try-catch","validationCode":"const av = await api.getAttributeView(avID);\nconst tplExists = !templateID || (av.newItemTemplates||[]).some(t => t.id === templateID);\nif (!tplExists) templateID = ''; // fall back to default detached item","typeGuard":null,"tryCatchPattern":"try {\n  return await api.createAttributeViewItem({avID, blockID, templateID});\n} catch (e) {\n  if (e.message.includes('not found') && e.message.includes('template')) {\n    return await api.createAttributeViewItem({avID, blockID, templateID: ''});\n  }\n}","preventionTips":["Resolve template IDs from the view's current template list, not cache","Pass empty templateID for default item creation","Re-fetch templates after any view reconfiguration"],"tags":["attribute-view","template","not-found"],"backgroundTag":"resource-not-found","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"}