plugin-templates
plugin-templates copied to clipboard
Add (string) comparison as helper function
Would it be possible, to include a custom helper function for Handlebars? I want to create templates based on the input upon creation. However, simple true/false evaluation doesn't do the trick for me. There are already solutions available, e.g. https://stackoverflow.com/questions/10736907/handlebars-js-else-if but I guess, that has to be included at the plugin level. In that question, one solution is to create an ifEquals function via:
Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) {
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
});
and then call it in the template via:
{{#ifEquals project "project 1"}}
Project 1 selected
{{else ifEquals project "project 2"}}
Project 2 selected
{{/ifEquals}}
Additionally, I also want to change the template_title
based on a variable or change the template_notebook
Hi @Engwer, you are welcome to contribute to this plugin and send a pull request. Your idea seems useful & interesting.
Implemented in https://github.com/joplin/plugin-templates/pull/79. This feature will go out in the next release.