-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Templater renames newly created notes to note name of note created previously #1326
Comments
I just redid all my code and made some minor adjustments which I did not think would have any meaningful impact, yet somehow doing so has fixed the issue. That means my code did have an issue after all, and this was not caused by the templater plugin. Apologies for the faulty bug report. |
What changes did you make? |
I changed it to this: async function newNote () {
// Load Templater API
const templater = app.plugins.plugins["templater-obsidian"].templater;
const tp = templater.current_functions_object;
let course;
let noteType;
let noteSubType;
// Clear file path
await tp.file.move("/" + tp.file.title);
// Filter out media files and send them to their own folder
if (tp.file.path(true).includes(".jpg") || tp.file.path(true).includes(".png")) {
(await tp.file.move("/Media/" + tp.file.title));
} else {
// Suggester for course selection
course = await tp.system.suggester(["Water 1", "Water 2"], ["Water 1", "Water 2",], true);
// Find note type base
noteType = await tp.system.suggester(["Courses", "Notes", "Terminology", "Questions"], ["Courses", "Notes", "Terminology", "Questions"], true);
// Start conditional based on noteType
if (noteType == 'Courses') {
await tp.file.move("/" + noteType + "/" + tp.file.title);
} else if (noteType == 'Terminology') {
noteSubType = await tp.system.suggester(["Concepts", "Events", "Theories"], ["Concepts", "Events", "Theories"], true);
await tp.file.move("/" + noteType + "/" + noteSubType + "/" + course + "/" + tp.file.title);
} else if (noteType == 'Questions') {
noteSubType = await tp.system.suggester(["Practice Questions", "Questions of Understanding"], ["Practice Questions", "Questions of Understanding"], true);
await tp.file.move("/" + noteType + "/" + noteSubType + "/" + course + "/" + tp.file.title);
} else if (noteType == 'Notes') {
noteSubType = await tp.system.suggester(["Lecture Notes", "Literature Notes", "Summaries", "Project Notes", "Meeting Notes", "Writing Notes"], ["Lecture Notes", "Literature Notes", "Summaries", "Project Notes", "Meeting Notes", "Writing Notes"], true);
await tp.file.move("/" + noteType + "/" + noteSubType + "/" + course + "/" + tp.file.title);
} else { window.alert("Error: Something went wrong in the note type selection");};
};
// Update noteType based on whether noteSubType was defined
if (noteSubType != undefined && noteSubType !== null) {
noteType = noteSubType;
};
// Define frontmatter based on noteType
switch (noteType) {
case 'Courses':
Frontmatter = `
---
fileClass: Base, ${noteType}
title:
Parents:
Draft:
Status:
Course Code:
Period:
Duration:
Timeslot:
Year:
---`;
break;
case 'Concepts':
Frontmatter = `
---
fileClass: Base, ${noteType}
title:
Parents:
Draft:
Status:
aliases:
Related Notes:
Related Terminology:
Related Courses:
---`;
break;
case 'Events':
Frontmatter = `
---
fileClass: Base, ${noteType}
title:
Parents:
Draft:
Status:
aliases:
Event Date:
Related Notes:
Related Terminology:
Related Courses:
---`;
break;
case 'Theories':
Frontmatter = `
---
fileClass: Base, ${noteType}
title:
Parents:
Draft:
Status:
aliases:
Authors:
Related Notes:
Related Terminology:
Related Courses:
---`;
break;
case 'Practice Questions':
case 'Questions of Understanding':
case 'Lecture Notes':
case 'Summaries':
Frontmatter = `
---
fileClass: Base, ${noteType}
title:
Parents:
Draft:
Status:
Related Notes:
Related Terminology:
Related Courses:
---`;
break;
case 'Literature Notes':
Frontmatter = `
---
fileClass: Base, ${noteType}
title:
Parents:
Draft:
Status:
Authors:
Year of Publication:
Related Notes:
Related Terminology:
Related Courses:
---`;
break;
case 'Meeting Notes':
Frontmatter = `
---
fileClass: Base, ${noteType}
title:
Parents:
Draft:
Status:
Meeting Date:
People Involved:
Related Projects:
Related Courses:
---`;
break;
case 'Project Notes':
Frontmatter = `
---
fileClass: Base, ${noteType}
title:
Parents:
Draft:
Status:
Project Type:
People Involved:
Related Notes:
Related Courses:
---`;
break;
case 'Writing Notes':
Frontmatter = `
---
fileClass: Base, ${noteType}
title:
Parents:
Draft:
Status:
People Involved:
Related Projects:
Related Notes:
Related Terminology:
Related Courses:
---`;
break;
default:
window.alert("Error: Seomthing failed in the metadata selection");
}
Frontmatter = Frontmatter.trim();
return Frontmatter;
};
module.exports = newNote; Basically, I moved the newly created file to the root directory earlier, and made sure all variables were initialised as part of the function to prevent cluttering. |
Plugin information
<% tp.user.newNote() %>
which refers to a custom script I wrote). Additional settings are a script folder /Scripts on the same level as the Templates folder. This script runs for all new notes created by having a folder template set for the folder/
Expected behavior
Though you usually start with the bug, I'd like to first describe what my script is intended to do. The script is meant to, upon new file creation, prompt the user for the course the note is related to (since it is used for my studies), and the type of note. Then, based on the results, choose a folder where to move the file to and add frontmatter specific to that note type. Though this is the first script I wrote by myself, it works quite well (except for the behaviour I will describe below, which I think might be a bug).
Describe the bug
What happens is quite strange, but I will try to write it in an as structured manner as possible. Note that the behaviour described above works perfectly and there are no issues there.
What happens is that the new file that gets created receives the name of the file created before it. I can best describe this by walking you through the process and showing what happens.
[[Test File 1]]
)[[Test File 2]]
)[[Test File 3]]
)In addition, every time the name is changed, so is the original link. Meaning that not only does the name of the note that is created change, so does the link in the place where the note was originally created
Script
My script is as follows:
Additional context
I run a few additional plugins, but I tried turning them all off and still see the same results.
I wrote a post on the obsidian forums before coming here (https://forum.obsidian.md/t/help-debugging-templater-script/77209), but they recommended I make a bug report.
Thanks in advance!
The text was updated successfully, but these errors were encountered: