Trying to create a weekly review from a daily note, with moments & tp.file.create_new

Thank you for reading. I am a beginner in many ways, and I fear this will be my undoing. I have tried to scour the help topics for something similar, but I am at the end of my wits and my patience, and the more sane thing to do is now to write this post. It is my first; I usually solve things by googling for topics on this forum!

What I’m trying to do

I usually create a Weekly Review on Mondays (=day[0] where I am) but sometimes I forget. So I wanted to write code, so that templater would be able to to do ths automatically, based on the weekday. And yes, if this works, I will implement the same principle for months, quarters and years.

Things I have tried

My daily note is quite elaborate, and it halted the entire thing. So I isolated this snippet to see if I could make it work on its own, and I used it on a note dated as a random Monday. I included frontmatter like it would appear in the intended file (there would be more, of course).

---
title: 2023-02-13
---
<%*
if (moment(tp.file.title).format("ddd") == "Mon") {
	template = tp.file.find_tfile("[[Periodic Note - Weekly]]")
	await tp.file.create_new(template)
};
-%>

Templater finds al kinds of errors, among others >template function call error<. I have also excluded template: await tp.file.create_new(), I have included the full monty: await tp.file.create_new(template, wk, true, dir) (with all those variables assigned, of course), and also with their filename and what not all written out.

I got the idea from Templater discussion #658, amongst other places. The condition seems to work on its own as well, just not in conjunction with create_new.

I admit I am a newb, with javascript level vanilla but no fear of experimenting. So I am sure my error is something simple I am just not grasping. Could anyone shine their brighter light? Thank you in advance!

Came back to add I also tried if (tp.date.now("ddd", 0, tp.file.title, "YYYY-MM-DD") === "Mon") in stead of moments.js.

I could be wrong, but I suspect that

template = tp.file.find_tfile("[[Periodic Note - Weekly]]")

should be

template = tp.file.find_tfile("Periodic Note - Weekly")

@ninjineer thank you for replying!

Unfortunately, this isn’t the issue. I tried both, and in all conjunctions I could think of. In the code above I use a placeholder for the template, I have done without, I had the dir both written out and assigned to a placeholder, I’ve had all args mentioned in Templater’s documentation on the matter for create_new:

tp.file.create_new(template: TFile ⎮ string, filename?: string, open_new: boolean = false, folder?: TFolder)

As the docs indicate, only the template is needed, the filename and folder are optional, and the open_new arg has a default. And upon running the template, the code disappears alright, but no new note is created, neither opened nor in the dir list.

The Weekly template has its own moving template, depending upon the date, so no folder needs to be indicated, I thought.

What could I be doing wrong?