I want to start a not, using a template that pre-write part of the title of the note
Example:
I want the note start saying "1-1 "+atendee+“YYYY-MM-DD”
I did this:
<%*
let title = tp.file.title;
if (title.startsWith(‘Untitled’)) {
title = await tp.system.prompt('Atendee: ');
await tp.file.rename("1-1 "+${title} +tp.file.creation_date(“YYYY-MMM-DD”));
}
-%>
<#[[% tp.file.title %>]]
It works perfect and add the attendee to the file name, but the line tp.file.title, continue saying “Unknown”
If I remove the code… for adding “1-1”… tp.file.title, works perfectly well, if I change the Unknown in the filename, the tp.file.title shows the change in the name.
Missed out on the extension of your title, but then you could store the full filename in a variable, and then use that later on in the file.
My main point that tp.file.title is set at the start of the template, and doesn’t change during the template execution is still valid (I think).
It could be argued that it possibly should change after a rename operation, but there are also valid reasons why it shouldn’t. So keeping track of it yourself is the better solution in this case.
If you want to counter for the case that the file isn’t renamed you could do it this way:
<%*
let title = tp.file.title;
let created = tp.file.creation_date("YYYY-MM-DD");
let attendee = await tp.system.prompt('Attendee: ');
if (title.startsWith('Untitled')) {
title = `1-1 ${attendee} ${created}`; // Set and store the new title
await tp.file.rename(title);
}
-%>
# [[<% title %>]]