Templater grabs file name before it is named

Alright, good to know that it’s working now.

As for how to split, it depends on what you want to achieve and what you are splitting. I can’t really help you without that information. But in any case, you shouldn’t put tp in this line: tp.newTitle.split(`-`)[1]. Also, you need to save it to a new variable, so that you don’t split the newTitle that you want to rename the file to. So it would be something like:

<%*
const title = tp.file.title;
let splitTitle;
if (title.startsWith("Untitled")) { 
    newTitle = await tp.system.prompt("Enter note title");
    splitTitle = newTitle.split(`-`)[1].trim();
    await tp.file.rename(newTitle);
}
-%>
---
splitTitle: <% splitTitle %>
---

If you are looking to save the second part after the -, then this looks right. I added a .trim() to remove unwanted whitespace.


If you don’t want to be prompted for a title, but were actually using tp.file.rename in folder templates before with predetermined titles, and that’s what you wanted, you could try fetching the title using tp.config.target_file.basename, like @TheTao recommended. However, in this case, you wouldn’t need to split anything, since it’s already predetermined, and you could just put that info directly in the templates frontmatter.