Templater
Templater copied to clipboard
Call tp.file.include with parameters to transmit variables
Problem
I have a template with a script using <%* %> and in there I define and use variables. Calling tp.file.include of another template doesn't carry the variables.
Solution
Having a way to carry the javascript variables from the calling template to another
- I don't know if this is possible or
- pass a JSON as a parameter to the tp.file.include call with a known variable name for the called template to use
- or some other easy mechanism
This is a must! I have complicated templates for bookmarks which require passing data between multiple templates, but there's no syntax for that as of now.
I propose either using the old {{var}} syntax or maybe tp.file.param("<name>").
You can always add params to either tp or window to pass variables around. For example:
<%*
tp.my_params = new Map();
tp.my_params.set("key", "value");
-%>
// in a sub template
<%*
console.log(tp.my_params.get("key"));
-%>