Template Selector Plugin

name

Template Selector

description

Select a [Template] from a specified tag with a GUI!

instructions


In the plugin settings,

Select the tag that contains the desired templates.

Then, simply use {Template Selector}!

setting

Tag with Templates

{
async insertText(app) {
// Fetch the templates from the specified tag
const noteHandles = await app.filterNotes({ tag: app.settings["Tag with Templates"] });
console.log("noteHandles:", noteHandles); // debug log
 
// Convert the note handles to a format suitable for the dropdown menu
const templateOptions = noteHandles.map(noteHandle => ({
label: noteHandle.name, // display the note title in the dropdown menu
value: noteHandle.uuid // return the note UUID when the option is selected
}));
console.log("templateOptions:", templateOptions); // debug log
 
 
// Prompt the user to select a template
const result = await app.prompt("Select a template", {
inputs: [
{
type: "radio",
options: templateOptions
}
]
});
console.log("result:", result); // debug log
 
if (result) {
const selectedTemplateUUID = result;
console.log("selectedTemplateUUID:", selectedTemplateUUID); // debug log
 
// Fetch the content of the selected template
const selectedTemplateContent = await app.getNoteContent({ uuid: selectedTemplateUUID });
console.log("selectedTemplateContent:", selectedTemplateContent); // debug log
 
// Insert the selected template into the current note
app.context.replaceSelection(selectedTemplateContent);
 
return null;
} else {
// User canceled
}
}
}