Templater icon indicating copy to clipboard operation
Templater copied to clipboard

Call tp.file.include with parameters to transmit variables

Open stecydube opened this issue 4 years ago • 2 comments

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

stecydube avatar Nov 22 '21 22:11 stecydube

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>").

Thundercraft5 avatar May 28 '25 16:05 Thundercraft5

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"));
-%>

Zachatoo avatar May 29 '25 04:05 Zachatoo