Templater
Templater copied to clipboard
"Destination file already exists" error after turning on Trigger Templater on new file creation setting
Plugin informations (please complete the following information):
- OS: MacOS 0.15.7
- Templater version: 1.9.9
- Obsidian version: 0.13.14
- Templater settings:
Describe the bug
This bug occurs after I turned on "Trigger Templater on new file creation". I have a template that uses the tp.file.include module referring to a child template. In the child template, there is a line of tp.file.rename. After I apply the former template, the error occurs and a new file is created as the picture below shows.
One solution i came up with would be to have an option that user can only enable the Folder Templates, so the plugin would not execute all scripts in newly created files despite they are not created in the folders that are specified in the setting.
Expected behavior include the child template into the file without the file creation.
Screenshots If applicable, add screenshots to help explain your problem.
the error
one extra file that is created
the code in the parent template
the code in the child template
The include
isn't triggering this error. It is likely you're trying to rename
the note to one that already exists after the include is run. There are a bunch of ways you could solve this but I'd need to understand more about what you're trying to accomplish with these commands.
The
include
isn't triggering this error. It is likely you're trying torename
the note to one that already exists after the include is run. There are a bunch of ways you could solve this but I'd need to understand more about what you're trying to accomplish with these commands.
I am trying to use a trigger symbol which is "-" in this case to include
a specific template. A have a bunch of them. Therefore, I only have to trigger the template with all these if statements, it will include the template i need depending on the first letter of file name. Then, i have a rename command in the template that is being included, so it will delete the trigger symbol in the front. The problem is that not file in that folder has the same name as the file name I am trying to rename to, resulting the error and two separate file. In the file with the "-", there is my if command. In the other file, there is the template being included successfully
Yeah so to avoid the filename conflict you could move the note to a different folder with tp.file.move
. The move command can also be used to rename.
Or you could look if the name already exists in the given folder and add a number to the filename to make it unique.
Do either of those work?
Yeah so to avoid the filename conflict you could move the note to a different folder with
tp.file.move
. The move command can also be used to rename.Or you could look if the name already exists in the given folder and add a number to the filename to make it unique.
Do either of those work?
I think what caused this problem is that the rename command was triggered twice. The first time is when i apply the template after the second template is being included. The second time is when Templater plugin detected the command and run it again. This is why when i turned off that setting, it would work just fine.
I'm having the same issue where I do "dash-Work" to activate a specific template then a child template with move and the old file name still exists...
meta template picker (for all new files) → picks the dashboard template
<%-* var trigger = (tp.file.title.split("-")[0]) %>
<%-* if (!tp.file.title.includes("-")) { %>
<%-tp.file.include("[[Default Note Template]]")%>
<%-* } else if (trigger.startsWith("dash")) { %>
<%-tp.file.include("[[Dashboard Template]]") %>
<%-* } else { %>
<%-tp.file.include("[[Default Note Template]]")%>
<%-* } _%>
Child template - The dashboard template than renames
<%-*
let title = tp.file.title
if (title.startsWith("dash")) {
title = "04 " + tp.file.title.split("-").slice(1).join('-') + " Dashboard";
myFilePath = "00 System/" + `${title}`
await tp.file.move(`${myFilePath}`);
}
-%>
mode:: #mode
kind:: #SystemMeta/Dashboard🚀
topics::
status:: #Status/Blank⚪
doc::
expected behaviour: one file "00 System/04 Work Dashboard" actual: two files (one is "00 System/04 Work Dashboard" and the other unwanted one is "dash-Work" in the main vault.
I had a similar issue when I was using move
but needed to be using rename
. If it's in the right folder already, rename
. If it's in another folder, move