Now that yaml comments and double quotes around yaml values are auto deleted when creating notes with templater, a workaround was required and found: add a blank line in the template before the yaml starts, then use a 2nd template to remove the blank line.
(Or maybe I can add something to the 1st template that says: ‘when done, go up to first empty line and remove it’?)
My issue is that I can manually call the 2nd template and it works, but I can’t seem to combine the templates into one. I tried using await, and I tried using include to call the 2nd template, but nothing works.
Can someone help?
1st template (default file creation template)
<%* const title = await tp.system.prompt("Title"); -%>
<%* const folders = this.app.vault.getAllLoadedFiles().filter(i => i.children).map(folder => folder.path);
const folder = await tp.system.suggester(folders, folders);
-%>
<%*
let titledate = title // note file name
let titleAddDate = tp.file.creation_date("YYYY-MM-DD") + " " + title
let isDate = (/^\d+-\d+-\d+/).test(title) // returns boolean
var result = ""
// check for presence of date in title
if(isDate){ // note title begins with YYYY-MM-DD
result = titledate
} else {
result = titleAddDate
}
titledate = result
-%>
<%*
let filename = title;
filename = filename.replace(/[\\\:*?<>|""]/g, "");
await tp.file.move(`/${folder}/${filename}`);
-%>
<%*
let yamlline = "---"
%>
<% yamlline %>
datecreated: <% tp.file.creation_date("YYYY-MM-DD") %>
titledate: "<% titledate%>"
title: "<% titledate.substr(11, title.length)%>"
aliases:
keywords:
- <% tp.file.folder(true).split('/').join('\n - ').toLowerCase() %>
status: active # archive, inactive
# personal
notes: >
<% yamlline %>
# <% titledate.substr(11, title.length) %>
<% tp.file.cursor(1) %>
2nd template (go up to 1st line and remove it)
I wonder if the issue is related to “activeLeaf”… because I am in the resulting file of template 1 when I call template 2. But if this template is inside my creation template, and I haven’t yet clicked on the new file because it isn’t finished being created, then maybe there is no
active leafto be found?
<%*
// Get the current file content
let content = tp.file.content;
// Split content by lines, remove the first line (index 0)
let lines = content.split('\n');
lines.shift();
// Join the remaining lines back together
let newContent = lines.join('\n');
// Update the file content
await app.workspace.activeLeaf.view.editor.setValue(newContent);
%>
Note: When I tested combining the two templates I did rename “content” here, because it is already being used in the 1st template.