Skip to content

fix: validate default template still has template tag before using it#134

Open
sh1vam31 wants to merge 1 commit intojoplin:masterfrom
sh1vam31:fix/validate-default-template-is-template_#107
Open

fix: validate default template still has template tag before using it#134
sh1vam31 wants to merge 1 commit intojoplin:masterfrom
sh1vam31:fix/validate-default-template-is-template_#107

Conversation

@sh1vam31
Copy link
Copy Markdown
Contributor

Fixes #107

If a note was set as the default template and later had its template tag removed, the plugin would silently fail or give a misleading error. It should instead inform the user that the saved default is no longer a template.

Fix

src/utils/templates.ts

  • Added isNoteATemplate(noteId) — checks if a note still has the template tag
  • Updated getTemplateFromId() to return null if the note is no longer a template

src/index.ts

  • Both "Create note from default template" and "Create to-do from default template"
    commands now show a clear, actionable error message:

"The note set as the default template is no longer a template.
Please set a new default template via Tools → Templates → Default templates."

Testing

  1. Created a note, tagged it as template, set it as the default template
  2. Removed the template tag from that note
  3. Clicked Tools → Templates → Create note from default template
  4. The correct error message appeared
  5. Re-added the template tag → default template worked normally again

@sh1vam31
Copy link
Copy Markdown
Contributor Author

@nishantwrp, Kindly review this PR.

Copy link
Copy Markdown
Collaborator

@alondmnt alondmnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this @sh1vam31. The approach and error messaging look good for the tag-based workflow.

One issue: isNoteATemplate hardcodes a check for the template tag, but when TemplatesSource is set to "Notebook", templates live in a "Templates" folder and don't need that tag. Since getTemplateFromId is shared, this would cause notebook sourced default templates to be incorrectly rejected.

The fix should respect TemplatesSourceSetting for notebook source, check that the note is in a "Templates" folder instead of checking for the tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check if the default template is actually a template

2 participants