Templater rename + use title on body

I’m trying to move a new file to a certain folder, then change it’s name from untitled to “Session (number) (date)” and then print that name on the body of my note

I mainly tried different iterations of a code that looks like this:
<%- await tp.file.move(“/folder/” + tp.file.title) %>
<%- tp.file.rename("Session " + tp.date.now()) %>
<% tp.file.title %>

Plus I haven’t been able to figure out how to keep track of the number of sessions using a variable.

I’m aware that it’s possible to create custom user functions but bear in mind that my knowledge of JS is very limited.

---
<%*
//Pop up a window to ask you to choose your subject
let Subject = await tp.system.suggester(["Subject1", "Subject2", "Subject3", "Subject4"], ["Sub1", "Sub2", "Sub3", "Sub4"], false, "Choose your Subject")

//Rename your note, add condition just in case you accidentally delete the note
let newTitle
if(tp.file.title.toLowerCase().includes('untitled')) {
newTitle = `${Subject}` + " " + tp.date.now("YYYY-MM-DD-HHmmss")
await tp.file.rename(newTitle)
}
else newTitle = tp.file.title

//Move the note to "Study/Subject/"
if(Subject !== null) {
let filePath = "/Study/" + `${Subject}` + "/" + `${newTitle}`
await tp.file.move(`${filePath}`)
}
%>
Subject: <% Subject %>
---

# <% newTitle %>
Topic:: 

Then turn on Templater’s Folder Templates function


whenever I create a note in the Study folder, it will use the above template.


I cannot get the “session-number” part working, but dataview plugin could help a bit, for example:

```dataview
Table Topic 
where Subject = "Sub1"
sort file.cTime asc

it basically means

  1. for all your notes that have yaml field Subject equals “Sub1”, create a table for them
  2. add a second column for the metadata field Topic.
  3. sort them in ascending order based on their creation time

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.