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.