This way to access the API, also shown here by @AlanG is really nice.
Here is my code snippet:
const tp = app.plugins.getPlugin("templater-obsidian").templater.current_functions_object
console.log(tp)
if (!tp) {
new Notice("Templater plugin not found. Make sure it is installed and enabled.");
return;
}
const templateFile = tp.file.find_tfile(templateName)
if (!templateFile) {
new Notice(`Template '${templateName}' not found`)
return;
}
await tp.file.create_new(templateFile, true, filePath)
Thing is, tp is undefined. Looking at the console log from this:
which doesn’t seem to have current_functions_object defined, and the file module I’m looking for is buried in a list. I can “dig” it out now that I know where to look, but it seems to me not a good way to do it as I will have to do it by index rather than name? And, TBH, I’m not sure if that “file” module is indeed the file module I am looking for
That could very well be the case, because there is a difference related to what is available when you’ve got an active editor leaf to work with, or not. I’ve gotten error messages from Templater when not having an active editor leaf, and I know that QuickAdd could still work at the same time (but I reckon with some limits).
In my case, that ‘current_functions_object’ is undefined until I use templater at least once. so I added startup template in templater settings. now ‘current_functions_object’ is always defined.