My pleasure !
Just in case , but here’s another idea to get the appropriate template inserted when needed :
If you have a different template for each weekday, this could work
<%*
// Array storing the needed templates
// 1 template for each day of the week
const templates = [
"[[Monday Temp]]",
"[[Tuesday Temp]]",
"[[Wednesday Temp]]"
// other templates ...
];
// Find out which template is needed "today" based on the isoWeekday
// number of "today" (where Monday = 1, Tuesday = 2, etc...)
// Minus 1 as arrays are zero-indexed
// So, if it's 0 it'll include "[[Monday Temp]]", if it's 1 > "[[Tuesday Temp]]", etc...
const tempIndex = moment(tp.file.title, "YYYY-MM-DD").isoWeekday() - 1;
tR += await tp.file.include(templates[tempIndex]);
%>
Now, if you don’t have a template to insert everyday, this could also work:
<%*
// Array storing the needed templates or blank ("") as a placeholder
// if there's no template to insert that day
const templates = [
"[[Monday Temp]]",
// Blank Tuesday placeholder
"",
"[[Wednesday Temp]]",
"",
"[[Friday Temp]]",
"",
""
];
// Find out which template is needed "today" based on the isoWeekday
// number of "today" (where Monday = 1, Tuesday = 2, etc...)
// Minus 1 as arrays are zero-indexed
// So, if it's 0 it'll include "[[Monday Temp]]", if it's 1 > "", 2 > "[[Wednesday Temp]]", etc...
const tempIndex = moment(tp.file.title, "YYYY-MM-DD").isoWeekday() - 1;
if (templates[tempIndex] != "") {
tR += await tp.file.include(templates[tempIndex])
}
%>
The if
might not be needed though … as far as I’ve tested it, if the value coming from the constant templates
is blank (""
), tp.file.include()
outputs “blank” in place of the template …
But again, it’s just an example
Edit: Corrected typos I’ve made ! Thanks Holroy !