Skip to content

fix: allow custom variable references in datetime helper attributes#164

Open
fuleinist wants to merge 1 commit into
joplin:masterfrom
fuleinist:fix/custom-variable-context-helpers
Open

fix: allow custom variable references in datetime helper attributes#164
fuleinist wants to merge 1 commit into
joplin:masterfrom
fuleinist:fix/custom-variable-context-helpers

Conversation

@fuleinist
Copy link
Copy Markdown

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:

template_todo_alarm: '{{datetime delta_days=days_until_due set_time="09:00"}}'

This fixes issue #161 where the README example was broken.

Problem

The README shows this example for setting a todo alarm:

template_todo_alarm: {{datetime delta_days=days_until_due set_time="09:00" format="YYYY-MM-DD HH:mm"}}

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

  1. 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.

  2. 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

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
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.

readme: template_todo_alarm example is broken

1 participant