I am trying to group my templates by purpose using dictionaries inside templater.
My aim is at reducing the number of template files and maintain them from a master template. At most, I think I will have 3 or 4 master groups: (i) for creation of classes or archetypes; (ii) intellectual production; (iii) devices inventory; (iv) papers collection.
I have the dictionary part of the classes for the properties practically done, thanks to @holroy and @gino_m. What I need now is to connected the templates that contain the dictionaries to a suggester which would allow to select the respective master template.
The problem I am facing is how to execute/run a template from the suggester selector. By execution I mean, running the template as we do with Alt+N
and then pick the template.
This is how the master selector, or “selector of templates”, looks:
selector of templates
<%*
const items = ["item 1", "item 2", "item 3"];
let subitems;
let selectedItem = await tp.system.suggester(item => item, items);
if (!selectedItem) {
// No selected option, user hit `Escape` key
return
}
switch (selectedItem) {
case "item 1":
subitems = ["template-11", "template-12", "template-13"];
break;
case "item 2":
subitems = ["template-21", "template-22", "template-23"];
break;
case "item 3":
subitems = ["template-31", "template-32", "template-33"];
break
default:
console.log("nothing")
}
console.log(subitems);
selectedItem = await tp.system.suggester(item => item, subitems);
console.log(selectedItem)
const file = tp.file.find_tfile(selectedItem);
// await app.vault.load(file);
// await app.vault.process(file);
// await app.vault.read(file);
-%>
And these are a couple of templates that I want to execute from suggester:
template-11
<%*
const classes = [
{ name: "My Articles",
prefix: "art",
folder: "My Stuff",
fields: {
summary: "",
tags: "content/article",
archetype: "[[My Stuff]]"
}
},
{ name: "My Posts",
prefix: "post",
folder: "My Stuff",
fields: {
summary: "",
tags: "content/post",
archetype: "[[My Stuff]]"
}
},
{ name: "My Repositories",
prefix: "repo",
folder: "My Stuff",
fields: {
summary: "",
tags: "content/repo",
archetype: "[[My Stuff]]"
}
},
]
console.log(classes);
tR += "We are at " + tp.file.title
tR += "\nClass Groups\n"
tR += "-------------------\n"
classes.forEach(item => {
tR += item.name;
tR += "\n";
});
%>
and:
template-21
<%*
const classes = [
{ name: "Devices",
prefix: "dev",
folder: "Inventory",
fields: {
summary: "",
tags: "inventory/devices",
archetype: "[[Inventory]]"
}
},
{ name: "Computers",
prefix: "comp",
folder: "Inventory",
fields: {
summary: "",
tags: "inventory/computers",
archetype: "[[Inventory]]"
}
},
{ name: "Audio",
prefix: "aud",
folder: "Inventory",
fields: {
summary: "",
tags: "inventory/audio",
archetype: "[[Inventory]]"
}
},
]
console.log(classes);
tR += "We are at " + tp.file.title
tR += "\nClass Groups\n"
tR += "-------------------\n"
classes.forEach(item => {
tR += item.name;
tR += "\n";
});
-%>
All this works but it just read the templates, they are not executed.
Any ideas?