You can also filter off a key symbol in the file name or even the path. I think this snippit came from @tallguyjenks sample vault a while ago. But it could easily be adapted to trigger off path instead of the first character.
Whenever I see blocks with so much repetitions, it just screams out to me to make it better through the use of a dictionary where you find the file to include with the character as a key. Similar to how we selected a given set of fields to include a few posts back.
<%*
const choices = [
{ name: "Books", char: "{" },
{ name: "Person", char: "@" },
{ name: "Tweet", char: "!" },
{ name: "Podcast", char: "%" },
{ name: "YouTube", char: "+" },
{ name: "Article", char: "(" },
{ name: "Paper", char: "&" },
{ name: "Thought", char: "=" },
]
for (var i=0; i < choices.length; i++) {
if (await tp.file.title.charAt(0) == choices[i].char) break
}
if (i == choices.length) {
new Notice("Character not found in title")
return
}
let choice = choices[i].name;
new Notice(choice);
switch(choice) {
case "Books":
// insert templater code here
break
case "Person":
// insert templater code here
break
case "Tweet":
// insert templater code here
break
case "Podcast":
// insert templater code here
break
case "YouTube":
// insert templater code here
break
case "Article":
// insert templater code here
break
case "Paper":
// insert templater code here
break
case "Thought":
// insert templater code here
break
default:
tp.file.include("[[Templates/General]]")
}
tR += choice
_%>
The JavaScript switch might not be necessary if you define your frontmatter inside choices. Fox example, adding a key fields to the dictionary/object. There are two options: (1) adding the frontmatter as a list of properties like @holroy suggested here: