I’ve been running tests with Templater js code to make a Meeting Note template that inherits YAML properties from another note (through Dataview’s API). I finally have everything working right, except that every time I trigger the template creation, an extra “Untitled” note is created.
Obsidian also automatically opens the “Untitled” file after note creation instead of the actual new Meeting Note.
My Code
What’s cool about this js template is the YAML inheritance from the Project Overview file. I’m not an experienced coder, so I created the script by modifying code from these useful posts:
Inherit or pass on Metadata Values from Active File when creating New File
Get Dataview inline field from different file using Templater
Here is the template:
<%*
// Prompt to select Project Overview file
// Applies filter to suggest relevant files
const pOverview = (
await tp.system.suggester(
(item) => item.basename,
app.vault.getMarkdownFiles().filter((file) => file.name.includes("§"))
)
).basename;
// Access Project Overview frontmatter with DataviewAPI
const pMeta = DataviewAPI.page(tp.file.find_tfile(pOverview).path);
// Generate the new file name in the desired format
const currentDate = new Date();
const formattedDate = currentDate.toISOString().slice(0, 10);
const newFileName = `❉ ${formattedDate} ${pMeta.Project} Meeting Note`;
// Prompt the user for Meeting Attendees
const attendees = await tp.system.prompt("Meeting Attendees (comma-separated)");
// Define the content for the new note with inherited metadata
const content = `---
class: Meeting Note
Project: ${pMeta.Project}
Artist: ${pMeta.Artist}
Date: ${formattedDate}
---
up:: [[${pOverview}]]
# ${newFileName}
Attendees:: ${attendees}
### Summary
## Notes
## Reflection
`;
const baseFolder = app.vault.getAbstractFileByPath(pMeta.file.folder)
await tp.file.create_new(content, `${newFileName}.md`, true, baseFolder);
_%>
Example:
Say I want to create a new meeting note for Project X
I already have a note “§ X - Overview” (“§” is used to denote a project file and to keep that file at the start of alphabetical lists)
YAML for the note “§ X - Overview” would contain -
Project: X
Artist: Y
1/ I open Command Palette and type/select “Templater: Create new note from template”
2/ I select the template file that contains the js code for my Project Meeting Note template
3/ I am then prompted (by tp.system.suggester) to select one of my Project Overview notes. The properties of this file will be used in to populate the meeting note template.
4/ I select “§ X - Overview”
5/ I am then prompted for “Meeting Attendees”, which I can type in.
6/ The new meeting note is populated with metadata inherited from “§ X - Overview”. The new note is automatically renamed with my chosen naming convention (“❉ YYYY-MM-DD X Meeting Note”) and moved into the same folder as “§ X - Overview”.
7/ For some reason, a new note “Untitled” has been created, placed in my default new note location (/Captures), and opened in my tab.
– The “Untitled” note seems to be created in between steps 2 and 3
Questions
Any idea why this extra “Untitled” note is being created?
None of my other templates use js, but they work without creating an extra unnecessary note. Am I missing something basic about Templater?