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!