Context
I’m creating a note that is titled after a certain location, and I would like Templater to automatically tell me which train station is connected to that location.
Where I am so far:
After a bit of back and forth with ChatGPT and after searching through forums I’ve ended up with this script that:
- Prompts a re-name of the file in case the file name is “Untitled”
- Splits the title
- Slices out the 4th and 5th word and defines this as “Location”
- Example: Note title: “Episode 1 - Warschauer Str.”
- Location = Warschauer Str.
The code that I have so far, which successfully does this, can be found here:
<%*
const title = tp.file.title;
let Location;
let LocationWithHyphen;
if (title.startsWith("Untitled")) {
newTitle = await tp.system.prompt("Enter note title");
const words = newTitle.split(' ');
if (words.length >= 5) {
Location = words.slice(3, 5).join(' ');
LocationWithHyphen = words.slice(3, 5).join('-');
} else {
Location = words.slice(3); // Handle the case where there are not enough words
LocationWithHyphen = words.slice(3); // Handle the case where there are not enough words
}
await tp.file.rename(newTitle);
}
-%>
What I’m trying to do
Make Templater force a check of the (new)title for a certain list of “keywords”, and if it matches any of the keywords, the <% line %> in the body of the note is replaced with the name of that list.
Example:
Note Title:
Episode 1 - Warschauer Str.
List 1 (U5):
Keyword1 = Warschauer Str.
List 2 (U2):
Keyword 2 = Gleisdreieck
In-line Example:
Location = <% location %> (Warschauer Str.)
Line = <% line %> (U5)
Things I have tried
Although I feel like I can pick apart the code I have ended up with so far, I’m not advanced enough to know what is is that I’m actually looking for, so I will refrain from posting broken code as this will only muddy the post.
Any help is appreciated!