First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.
What I’m trying to do
I am trying to have a different template for my daily note for every day of the week e.g. I want one template that is generated on Mondays, another that is generated on Tuesdays and so on.
Things I have tried
Just a few things:
- I am confident that templater is working correctly and has all the things enabled it needs.
- The idea is to have a main note that serves as the template for the daily notes that compies in from a different template depending on the day of the week.
I was trying the following code (essentially generated by ChatGPT because I have no idea how JS works but I my a few adjustments):
<%*
const futureDate = tp.file.title; // Der Titel der Datei im Format DD-MM-YYYY
const [dayPart, monthPart, yearPart] = futureDate.split(“-”); // Zerlege den Titel in Tag, Monat, Jahr
const dateObject = new Date(${yearPart}-${monthPart}-${dayPart}
); // Erstelle ein Date-Objekt im Format YYYY-MM-DD
// Array der Wochentage, um den Tag-Index zu übersetzen
const weekdays = [“sunday”, “monday”, “tuesday”, “wednesday”, “thursday”, “friday”, “saturday”];
const day = weekdays[dateObject.getDay()]; // Ermittelt den Wochentag und wandelt ihn in Kleinbuchstaben um
// Debug output: Check what path is generated
tR += Generated Template Path: [[${day}]]\n
; // Gib den generierten Pfad aus
// Save the template path for later use
const templatePath = "[[${day}]]"
;
tp.file.include(templatePath)
%>
but it only include Generated Template Path: [[${day}]]\n
in the file. What is really confusing to me is that when I use the code block
<%
tp.file.include(“[[monday]]”)
%>
everything works fine i.e. it includes the contents of the file monday.md into my daily note. However when I use the code
<%*
const futureDate = tp.file.title; // Der Titel der Datei im Format DD-MM-YYYY
const [dayPart, monthPart, yearPart] = futureDate.split(“-”); // Zerlege den Titel in Tag, Monat, Jahr
const dateObject = new Date(${yearPart}-${monthPart}-${dayPart}
); // Erstelle ein Date-Objekt im Format YYYY-MM-DD
// Array der Wochentage, um den Tag-Index zu übersetzen
const weekdays = [“sunday”, “monday”, “tuesday”, “wednesday”, “thursday”, “friday”, “saturday”];
const day = weekdays[dateObject.getDay()]; // Ermittelt den Wochentag und wandelt ihn in Kleinbuchstaben um
// Debug output: Check what path is generated
tR += Generated Template Path: [[${day}]]\n
; // Gib den generierten Pfad aus
// Save the template path for later use
const templatePath = "[[${day}]]"
;
tp.file.include(“[[monday]]”)
%>
It seems like the command tp.file.include() doesn’t work anymore and I get and error that I need to link an existing Obsidain file, even tough I hard coded the correct link into the command. For me the relly confusing part is that tp.file.include(“[[monday]]”) seems to work by itself but not after I have some other code.