There is more to be said on this subject, which might not be very clear from the documentation.
Various ways to insert templates
One way to trigger Templater is as you’ve discovered through applying/inserting the template when you create a file.
However, you can also insert a template into any file open for editing, either through the command: Templater: Open Insert Template modal, where you select which template to insert, or through Template Hotkeys-commands.
I’ve added a hotkey for my custom command: Templater: Insert _templates/zTemplate.md. This command was added from Settings > Templater > Template Hotkeys. There I selected my
_template/zTemplate.md, and later on assigned a hotkey to this template. This allows me to hit that hotkey, and insert that template whenever I want into the active file.
Yet another way to trigger templates, is through other plugins, like the buttons-plugin, where you can do stuff like:
type append template
Which could produce output like the image below when you hit the button:
Different run variants of templates
In addition to these ways to insert the templates, there are even more ways to trigger the Templater engine. Try adding the following to a file:
%: <% tp.file.last_modified_date() %>
%+: <%+ tp.file.last_modified_date() %>
%\* : <%* tp.file.last_modified_date() %>
%\* tR: <%* tR += tp.file.last_modified_date() %>
%\*+ tR: <%*+ tR += tp.file.last_modified_date() %>
If I goto the reading view for this file without doing anything else, I get:
Here you can see that the
<%+ and the
<%*+ tR lines are actually executed, and produces the last modification date of my file. Other Templater code can be executed the same way. So the
+ makes it a dynamic template, where the result is shown in the reading view. Note that this is a non-destructive way of triggering the Templater engine, as the code in the file stays the same.
The final way, that I know of, to trigger the Templater engine, can be done with the same file, by executing the command: Templater: Replace templates in the active file. If I do this in the file mentioned above (after removing the last line,
%\*+ tR, which triggers an error in this case), it replaces (aka destructive editing) the templates of the source file, with:
%: 2023-01-02 18:04
%\* tR: 2023-01-02 18:04
Here you see that it executes the various templates, and replaces text accordingly to its normal rules. So the first and the fourth (remember the last needs to be removed for this to work), do get the actual last modification date of the file (when the command ran). The second has a little strange response (as it is meant to produce output in the reading view). The third, doesn’t produce any output, since the
tR variables wasn’t changed.
I hope this was illuminating, and food for thoughts on various ways to utilise the Templater plugin. Some documentation on this last part on various incantations of the Templater engine, can be found at Commands - Templater.