fix: allow custom variable references in datetime helper attributes#164
Open
fuleinist wants to merge 1 commit into
Open
fix: allow custom variable references in datetime helper attributes#164fuleinist wants to merge 1 commit into
fuleinist wants to merge 1 commit into
Conversation
The datetime helper's delta_days (and similar attributes) can now reference
custom variable names defined in the template frontmatter. For example:
template_todo_alarm: '{{datetime delta_days=days_until_due set_time="09:00"}}'
This fixes issue joplin#161 where the README example was broken because the
datetime helper received literal strings instead of resolved values.
## Changes
- src/helpers/datetime.ts: Added variable resolution logic to look up context
variable values from Handlebars 'this' and 'options.data.root'
- src/parser.ts: Updated to use processed variable values (numbers, dates)
in the context when compiling special variable templates
## Testing
- Added unit test for custom variable reference in delta_days attribute
- All 99 tests pass
Fixes joplin#161
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The datetime helper's delta_days (and similar time-based attributes) can now reference custom variable names defined in the template frontmatter. For example:
This fixes issue #161 where the README example was broken.
Problem
The README shows this example for setting a todo alarm:
However, this was broken because when the datetime helper is called within the template compilation context, Handlebars passes the literal string "days_until_due" to the helper instead of resolving it to the actual variable value.
Solution
src/helpers/datetime.ts: Added variable resolution logic that looks up context variable values from Handlebars 'this' and 'options.data.root'. When an attribute value is a string that matches a context variable name, it resolves to that variable's actual value.
src/parser.ts: Updated to include processed variable values (numbers, dates, etc.) in the Handlebars context when compiling special variable templates. This ensures the datetime helper can resolve variable names to their actual values.
Testing
Fixes #161