Skip to content

Comments

Add {{ notebook }} template variable support (#105)#137

Open
Aaravanand00 wants to merge 1 commit intojoplin:masterfrom
Aaravanand00:add-notebook-name-variable
Open

Add {{ notebook }} template variable support (#105)#137
Aaravanand00 wants to merge 1 commit intojoplin:masterfrom
Aaravanand00:add-notebook-name-variable

Conversation

@Aaravanand00
Copy link

Summary

This PR adds support for a new template variable:

{{ notebook }}

The variable resolves to the name of the notebook in which the note is instantiated.

This addresses #105.


Behavior

When a template contains:

title: "{{notebook}} - Meeting Notes"

or inside the body:

# Notes for {{notebook}}

It will be replaced with the current notebook name at instantiation time.

If notebook context is unavailable, the variable resolves to an empty string (fails gracefully without errors).


Implementation Approach

  • Updated getDefaultContext() to asynchronously retrieve notebook information.
  • Used joplin.workspace.selectedFolder() to get the current notebook ID.
  • Used joplin.data.get(['folders', folderId]) to retrieve the notebook title.
  • Updated parseSpecialVariables() to support async context resolution.
  • Ensured graceful fallback if notebook data cannot be retrieved.
  • No unrelated logic was modified.

The change is minimal, isolated, and fully backward compatible.


Test Coverage

Added dedicated tests covering:

  • Correct resolution of {{ notebook }}
  • Graceful handling when notebook context is missing
  • Variable support inside template titles
  • Compatibility with existing variables

All tests pass:

  • 29/29 parser tests
  • 7/7 template tests
  • ESLint clean
Screenshot 2026-02-21 093702

Design Considerations

  • No new dependencies introduced
  • No breaking changes
  • Existing templates continue to function unchanged
  • Variable resolution integrates cleanly with the existing templating system

Please let me know if you would prefer an alternative naming convention (e.g., {{ notebook_name }}) for consistency with existing variables.

- Add notebook variable that resolves to current notebook name
- Gracefully handles missing notebook context (returns empty string)
- Works with both tag-based and notebook-based template sourcing
- Works in template body and title
- Add comprehensive unit tests covering all scenarios
- Update mock API to support workspace and data operations
- All existing tests continue to pass
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.

1 participant