I saw your post a little earlier on, but its been a busy day, so good for you that you found out of it. I first saw the Templater api referenced by @AlanG here: How to calculate my work hours - #8 by AlanG
And there he doesn’t pull out a single function like you do, which indeed is a neat trick, but he rather pulls out the “default” tp
object:
const tp = app.plugins.plugins["templater-obsidian"].templater.current_functions_object
And then uses the various functions like you do in a template, like doing tp.system.prompt()
. I kind of like that approach, but this a matter of personal preferences.
Whilst on a similar topic, I would also like to mention two alternatives which might be useful for other use cases:
- Using
dv.view()
functions, which is also a way to access a user defined javascript function. It’s the dataview alternative, so it’s a little directed towards producing a view of something with the possibility to attach dedicated CSS as part of the function. See Codeblock Reference - Dataview - Plugins like GitHub - saml-dev/obsidian-custom-js: An Obsidian plugin to allow users to reuse code blocks across all devices and OSes , which allows you to write your own javascript classes and include them into your various javascript files. This plugin provides a little framework to make it easier to build your javascript utility libraries.
So depending on your use case, either of these could be slightly better suited for the task at hand, but I just wanted to mention them to kind of broaden the view of alternatives available.