To use script user functions, you need to specify a script folder in Templater's settings. This folder needs to be accessible from your vault.
Let's say you specified the
Scripts folder as your script folder in Templater's settings.
You can then create your script named
.js extension is required) for example.
Scripts should follow the CommonJS module specification, and export a single function.
Let's have an example with our previous script
.js files) scripts in the
You will then be able to call your scripts as user functions. The function name corresponds to the script file name.
In our previous example, a complete command invocation would look like this:
Which would print
Message from my script: Hello World! in the console.
In script user functions, you can still access global namespace variables like
However, you can't access Eta scoped variables like
tR. If you want to use them, you must pass them as arguments for your function.
You can pass as much arguments as you want to your function, depending on how you defined it.
You can for example pass the
tp object to your function, to be able to use all of the internal variables / functions of Templater:
<% tp.user.<user_function_name>(tp) %>