Templater icon indicating copy to clipboard operation
Templater copied to clipboard

How best to trigger template insertion from another plugin, ideally with custom js context?

Open kevboh opened this issue 2 years ago • 5 comments

I'm building a plugin that uses templates to create specific notes. These notes have custom metadata that needs to be inserted into them. With the core templates plugin, I'm just replacing {{token}} with a value, but if a user is using Templater I'd like to be able to use Eta syntax instead. This question has two parts:

  1. Is the right API to call here templater.create_new_note_from_template?
  2. Is there a way to inject metadata such that <%= some_variable_from_metadata %> resolves correctly?

In the meantime I'll use the {{token}} method in Templater templates as well, but I'd love to do it the right way. Thank you!

kevboh avatar Feb 21 '22 14:02 kevboh

Can you reach out to me on Discord? I feel like I saw this a while back.

AB1908 avatar Mar 01 '22 22:03 AB1908

Bump. Is there any prefered way of injecting data into templates? In my case I want to inject some data into notes created by Periodic Notes plugin. The journey looks like that:

  1. Periodic Notes creates a new note
  2. My plugin fetches some data from external source and inject that into note as variables
  3. Templater style the note using the data

I can hack into Templater's interals or hook into a file creation and depend on Templater's Trigger Templater on new file creation setting. Then prefill the file with a Javascript code, that define my data. There are also interesting User Scripts mechanism in Templater, but I don't think I can integrate it with my plugin in the way I want. The user script can no call 3rd party plugin's method and I don't want to move all the logic into script.

KGrzeg avatar May 09 '22 14:05 KGrzeg

Hmm use CustomJS inside user script?

AB1908 avatar May 09 '22 20:05 AB1908

Yea, but I don't want to do all the stuff in the userscript, like request authentication. That be perfect if userscript could call my plugin's method and get returned data.

KGrzeg avatar May 10 '22 12:05 KGrzeg

Hold on, what do you mean by auth outside CustomJS? You'd rather do auth in templater?

AB1908 avatar Jul 15 '22 22:07 AB1908