Templater - rename file THEN move it to folder

I’ve created a template for my book notes, that moves the note to my book folder upon creation. It also sets the main header as the note’s title. I use Templater to do this:

<% await tp.file.move("path/to/book/folder/" + tp.file.title) %>

# [[<% tp.file.title %>]]

I’d like to add a prefix to the note upon creation, book - . To do this I added this Templater line:

<% tp.file.rename("book - ") %>
<% await tp.file.move("/knowledge-bases/1.general/2 - sources/0 - inbox/" + tp.file.title) %>

# [[<% tp.file.title %>]]

It all works well, except <% tp.file.title %> gets set to “Untitled”, i.e doesn’t take into account the prefix I’ve added.

Is there a way to ensure this line <% tp.file.title %> is run AFTER this one <% tp.file.rename("book - ") %> ?

First, tp.file.move can also rename the file, so you can do that in one step.

<%* await tp.file.move("/knowledge-bases/1.general/2 - sources/0 - inbox/book-" + tp.file.title) -%>

This is a known issue where the title changes but templater hasn’t caught up with the name change. To get around this you can use:

# <% tp.config.target_file.basename %>

5 Likes

Works like a charm, many thanks @shabegom !

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