`tp.file.include()` seems to not work in multiple lines of code!

What I’m trying to do

I am trying to make the following code work (the code is in a template):

<%*
tp.file.include("[[NOTE]]")
%>

For clarifacation the command works perfectly well for me when I do it in 1 line i.e.

<% tp.file.include("[[NOTE]]") %>

does what it is supposed to do and includes NOTE when I create a new note with the template. I really have know idea why it doesn’t work in the multiline version or how to fix it. But I need it in a multi line envirment since I want to include a note based on what day of the week it is and for that I need a variable that takes a value based on the current date and I think that can only work with multiple lines. Specifically I would like something like this to work:

<%*
let day = tp.date.now("dddd");
day = day.toLowerCase();
tp.file.include("[[${day}]]")
%>

Things I have tried

I have only really tried to modify the code a bit. But since I am not familar with JavaScript or the Templater Plugin that kind of let nowhere. I also asked ChatGPT but that didn’t help :frowning: It would be really cool if someone shares a solutions for this since it’s driving me kind of insane.

GPT will not help you.
Using the execution type (<%*) templater block you have to explicitly output the result with tR:

tR += await tp.file.include("[[${day}]]")

https://silentvoid13.github.io/Templater/commands/execution-command.html

1 Like

Thank you! I actually tried that but I didn’t know that the await was necessary.

1 Like

yep! a good rule of thumb is any time you have javascript doing something that requires file i/o you’re likely to need an await. You’ll usually end up with a bunch of output instead otherwise