Templater
Templater copied to clipboard
Mechanism to share functions/variables across template files
Is your feature request related to a problem? Please describe.
I've defined a bunch of helper functions and common variables to use across multiple templates to reduce verbosity. They frequently rely on tp.file
and tR
.
In order to have access to them in each template, I currently need to copy/paste the definitions into a <%* %>
block
Extracting the helper functions and constants into a separate file and using <%* tp.file.include %>
doesn't let me use variables/helpers defined in the external file because the included file logic gets run after the entire main file logic.
Describe the solution you'd like
Something like a "startup script" feature to let me centralize helper function and variable definitions where I still have access to the tp
and tR
objects from Eta
alternatively
An option for include
to run the logic from the included file before the current file
An option for
include
to run the logic from the included file before the current file
Or after, would also be nice.
Use case: Possibly "live" include code/template snippets and have them use the local (including) notes’ front matter data. Thus the "after".
Templater creates an instance of the tp object when you run a script. That object is accessible at all times and by all files until script execution ends. Write anything you need to access across all includes to the tp object (as in tp.mystring = "hello world"
).