Just need finishing touches on this life changing Templater template

I can’t code, but with the help of Google, smart people on Discord, and ChatGPT, I’ve almost completed this essential Template (still think there must surely be a plugin that does this, seems so obvious).

What it does, is that everytime a new note is created in the default new note folder, I get prompted, via a modal, to name the file and select a folder. The appropriate template is automatically applied based on my folder choice.

In effect, this means that if I click the main “Create new note” button, or if I click on an unresolved internal link, the modal ensures that the resulting new note is named, correctly located, and correctly templated. Essential for creating notes without friction, without having to manually find the right folder in explorer, without manually having to apply any commands.

It works perfectly when I create a new untitled note. But when I click on an unresolved internal link (which is essentially pre-named already) the modal ignores the name given in the internal link, and prompts me to name it again. Annoying if the name is long and I have to retype it.

So I’m looking for a tweak that in the event where the file is pre-named, the modal should either skip the naming step, or pre-populate the name field with whatever is in the internal link.

Took me ages to get this template working so any solution that is sturdy and simple would be my preference.

Here is the template

<%*
let qcFileName = await tp.system.prompt("Note Title");

// Define folder paths
const folders = {
	"1": "Notes/Other notes",
	"2": "undefined"

};

// Define templates for each folder
const templates = {
    "1": "[[Default note]]",
    "2": "[[Email Template]]",
};

// Create a selection prompt
let folderSelection = await tp.system.prompt("Select folder: 1 for Other notes, 2 for undefined");
let folderPath = folders[folderSelection];

let titleName = qcFileName;
await tp.file.rename(titleName);
await tp.file.move("/" + folderPath + "/" + titleName);

// Apply the corresponding template based on folder selection
tR += await tp.file.include(templates[folderSelection]);
-%>

Thanks but template failed to apply

Solved by integrating this script

Final script below. Obviously the idea is to add more folders and templates to the script.

<%*
let qcFileName = tp.file.title;
if (qcFileName.startsWith("Untitled")) {
    qcFileName = await tp.system.prompt("Note Title");
}

// Define folder paths
const folders = {
    "1": "Notes/Other notes",
    "2": "undefined"
};

// Define templates for each folder
const templates = {
    "1": "[[Default note]]",
    "2": "[[Email Template]]",
};

// Create a selection prompt
let folderSelection = await tp.system.prompt("Select folder: 1 for Other notes, 2 for undefined");
let folderPath = folders[folderSelection];

let titleName = qcFileName;
await tp.file.rename(titleName);
await tp.file.move("/" + folderPath + "/" + titleName);

// Apply the corresponding template based on folder selection
tR += await tp.file.include(templates[folderSelection]);
-%>

Highly recommend this script to one and all

1 Like

Please don’t post AI-generated solutions — it’s not helpful. If you don’t know the answer, leave the question for someone who does.

6 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.