Comments (3)
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.
from templater.
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.
from templater.
What changes did you make?
from templater.
Related Issues (20)
- Templater script inserting newline before front matter HOT 3
- Don't Include Frontmatter in Output HOT 2
- Folder Notes take priority when creating file HOT 7
- Expand metadata in space - Geolocation coords support request HOT 3
- Console error: app.js:1 No file creator assigned to create file with extension com. Falling back to markdown file creator. HOT 1
- Error: Failed to List Templates, No Template Folder Configured HOT 8
- Execution of the tp.file.selection() function erase the selection in the note HOT 2
- Add note about modified date to the FAQs / docs
- front matter formating number as a string HOT 1
- main.js missing HOT 3
- Date not rendered as link HOT 1
- 2.3.2 broke my frontmatter processing template HOT 6
- Auto jump to cursor is triggered twice on new file creation HOT 4
- invalid reference date format, try specifying one with reference format HOT 4
- bug: app.workspace.getLeaf().openFile() replaces content in a note if called without "await"
- app.fileManager.processFrontMatter doesn't work HOT 1
- Templater should parse, merge and write out frontmatter gracefully HOT 6
- Applying Text Color in Obsidian Without Unwanted New Lines HOT 2
- Templater no longer works with console error "Plugin failure: templater-obsidian TypeError: c is not a constructor" HOT 2
- The recent upgrade of this plug-in has broken "Trigger Templater on new file creation" HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from templater.