How to rename title w/ tp.file.rename but add <% tp.date.now("ddd MMM-DD-YYYY")%> in to it

Things I have tried

<%*
  let title = tp.file.title
  if (title.startsWith("Untitled")) {
    tp.file.rename("DreamLog");
  } 
  tR += "---"
%>
<% tp.file.cursor() %>

What I’m trying to do

I would like to add the date into the title using templater’s function, but it wont work.

<%*
  let title = tp.file.title
  if (title.startsWith("Untitled")) {
    tp.file.rename("DreamLog"<%tp.date.now("ddd MMM-DD-YYYY")%>);
  } 
  tR += "---"
%>
<% tp.file.cursor() %>

My goal here is so that anytime i create a new note inside of my “Dream” templater automatically renames it to “Dream Log December 23 2022” (today’s date)

It seems that adding another “<%” into the code breaks it but im not sure how to fix it.
What is the solution and where would i be able to find this kind of solution next I have to write some code like this?

I seem to have found the answer!

<%*
  let title = tp.file.title
  if (title.startsWith("Untitled")) {
    tp.file.rename("DreamLog " + tp.date.now("ddd MMM-DD-YYYY"));
  } 
  tR += "---"
%>

The solution was to add + tp.datenow("ddd MMM-DD-YYYY")

1 Like

Please do use await tp.file.rename( ... ), unless you want strange and sometimes random behavior out of your code.