joplin / plugin-templates

Create templates in Joplin and use them to create new notes and todos.
MIT License
164 stars 24 forks source link

Deprecate custom_datetime #94

Open nishantwrp opened 2 months ago

nishantwrp commented 2 months ago
janklostermann commented 3 weeks ago

This plugin in v2.4.0 on Windows cannot handle the formatting that you proposed as favorable: {{ datetime format="[]YYYY[-]MM[-]DD[ ]HH[:]mm[:]ss" }}

It throws an error:

(In plugin: Templates)

There was an error parsing that template, please review it and try again.

TypeError: (lookupProperty(...) || (depth0 && lookupProperty(...) || container.hooks.helperMissing).call is not a function

Could it be that this functionality has not been developed yet and your issue is a weired kind of a feature request?

janklostermann commented 3 weeks ago

I would desire a more general date formatting option as well, that does not only work for datetime through #custom_datetime but works for all variables of type date.

janklostermann commented 3 weeks ago

Handlebar.js helper could be the way to go (as Handlebar.js is the underlying template engine). The most primitive solution would be something across these lines:

Handlebars.registerHelper('YYYY', function (date) {
  const d= new Date(date);
  const year = d.getFullYear();
    return year
})

with template definition like

---
 start: date
---

# Start of Note
{{YYYY start}}

with startconfigured as "1923-01-01" at note creation would produce:


Start of Note

1923


The easiest implementation would be a config field in the plugins config, where (power) users could define these Helpers in JavaScript through a text field. And yes, I am aware, that this could open up security concerns with unsafe code snippets, and also significant debugging problems. Maybe through a testing like on the Handlebar Playground before saving as new config, these issues could become less problematic.

janklostermann commented 3 weeks ago
  • Mark custom_datetime as deprecated in favour of {{ datetime format="[]YYYY[-]MM[-]DD[ ]HH[:]mm[:]ss" }}
  • (Optional - Non blocking for 3.0.0) Show a one-time deprecation notice if anyone uses custom_datetime.

Sorry nishantwrp, only now I realize that this was a note by yourself as the maintainer/developer of that plugin. Thanks for all your work. I am looking forward for such generalization. Please go the full way for custom-defined date / time variables as well.