What I’m trying to do
I am trying to use Templater, specifically the tp.file.include() function to add a section to my daily notes for an annually recurring set of journal prompts. I have one template (i.e., Prompts.md) with sections (i.e., 001-366). Each section will contain the journal prompt content.
In my daily note, I want to look up the correct template and section based on the tp.date.now(“DDDD”) and pass that to the tp.file.include() function.
Things I have tried
So far, I’ve been able to independently declare the variable for the prompt using:
<%*
// Lookup Prompt Number based on calendar day (i.e., 1-366)
const prompt = “Prompt#” + tp.date.now(“DDDD”);
%>
I’ve also been able to successfully execute the tp.file.include() function, when I’ve manually specify the destination link, as shown below:
// Add Prompt file section contents to new note
<% await tp.file.include(“[[Prompt#001]]”);
%>
However, when I try to combine the too and make the process dynamic it seems to breakdown:
<%*
// Lookup Prompt based on calendar day (i.e., 1-366)
const prompt = “Prompt#” + tp.date.now(“DDDD”);
// Add Prompt file section contents to new note
tR+= await tp.file.include(“[[prompt]]”)
-%>
I’ve also tried a number of variations for passing the variable prompt to the tp.file.include() function. Best case, the error report says that the file doesn’t exist. Other attempts:
tR+= await tp.file.include(‘[[ ${prompt} ]]’);
tR+= await tp.file.include(“[[ <% prompt %> ]]”);
tR+= await tp.file.include([[prompt]]);
tR+= await tp.file.include(prompt);
I’m very much a novice with Javascript, so not sure if I’m missing the obvious issue/solution. My attempts at searching for solutions turned up some references to Nested Templates. I got some of the ideas on other ways to pass the variable to the tp.file.include() function. Any assistance/guidance would be greatly appreciated.