Templater icon indicating copy to clipboard operation
Templater copied to clipboard

tp.file.creat_new creates an empty note even when the template is given

Open Archie-2021 opened this issue 2 years ago • 9 comments

Plugin information (please complete the following information):

  • OS: Windows 10
  • Templater version: 1.12.0
  • Obsidian version: 0.14.15
  • Templater settings: [e.g. Template folder location: "Templates/", Timeout: "5" (add the templates not working with their associated command)]

Describe the bug i am trying to use tp.file.create_new , most of the time i get an empy note eventho the argument is for file content via tfile and string in separate cases. the weird thing about it is that same code work sometimes, somtimes it doesn't. maybe it has something to do with handling system resources. i never had such an issue before

Expected behavior to create the note with given template

Screenshots If applicable, add screenshots to help explain your problem.

Additional context here the code i am using, i have a very similar code that somehow still working too

<%* 
const nameVar = "here is a name at 2022-06-10"
const templateVar = tp.file.find_tfile("TemplateTest7")
await tp.file.create_new(templateVar, nameVar)
%>
<%* 
await tp.file.create_new("hello world", "something something 2022-06-10") 
%>

Archie-2021 avatar Jun 10 '22 13:06 Archie-2021

And I just realized no other plugin (like QuickAdd for example) is able to create a note with a template. As soon as I disable Templater plugin the template is in, maybe something happened in last update. I don't know what else to do and this is seriously disrupting my workflow. Please help

PS. it appears that uninstalling and reinstalling the plugin fixed the issue for me. thank you

Archie-2021 avatar Jun 12 '22 14:06 Archie-2021

And the bug is back after while. I have no idea how to live with it . I can't uninstall and reinstall Templater every time this happens. Please help me

Archie-2021 avatar Jun 14 '22 06:06 Archie-2021

@Archie-2021, I've tried your commands on a test vault and it works fine.

<%* 
const nameVar = "here is a name at 2022-06-10"
const templateVar = tp.file.find_tfile("TemplateTest7")
await tp.file.create_new(templateVar, nameVar)
%>

The above creates a new file with the correct name and template. File name "here is a name at 2022-06-10" with the contents from the "TemplateTest7" file.

<%* 
await tp.file.create_new("hello world", "something something 2022-06-10") 
%>

This creates a new file titled "something something 2022-06-10" with "hello world" inside.

Both works fine. demo

welpdx avatar Jun 14 '22 17:06 welpdx

@Archie-2021, I've tried your commands on a test vault and it works fine.

<%* 
const nameVar = "here is a name at 2022-06-10"
const templateVar = tp.file.find_tfile("TemplateTest7")
await tp.file.create_new(templateVar, nameVar)
%>

The above creates a new file with the correct name and template. File name "here is a name at 2022-06-10" with the contents from the "TemplateTest7" file.

<%* 
await tp.file.create_new("hello world", "something something 2022-06-10") 
%>

This creates a new file titled "something something 2022-06-10" with "hello world" inside.

Both works fine. demo demo

Yes I figure out that there is nothing wrong with code. I reinstalled the Templater and the issue is solved for now. It was causing some other plugins to create empty notes too. I could not figure out what is related to, but it was connected to Templater as disabling it fixing it.

Archie-2021 avatar Jun 14 '22 20:06 Archie-2021

It was causing some other plugins to create empty notes too

it was connected to Templater as disabling it fixing it.

https://i.imgur.com/l0cJuQC.gif I can think of some scenarios in which it causes creation of empty notes:

  1. If you used Alt + N Templater: Create new note from template Instead of Alt + E Templater: Open Insert Template Modal
Example demo

If you have Trigger Templater on new file Creation enabled and:

  1. If you have another tp.file.create_new command in your TemplateTest7. When you run the first command above, you are creating a new file with content from TemplateTest7. If this TemplateTest7 contains a tp.file.create_new command, when it's content is added to the new file, the tp.file.create_new will run.

  2. If you have both Folder Templates enabled. When your run the above commands, you are creating two files, which also triggers the Folder Templates.


Other than these three things, I can't think of anything else. If it is not the above 3, maybe it is to do with other plugins?

welpdx avatar Jun 14 '22 21:06 welpdx

interesting I never noticed there is a create a new not with this template command too, I don't have any hotkey assigned to it, I either use modal command or run a Templater form command pallet or some plugin and when I test it after you mentioned it I got an empty note (which I suppose should not happen.

That said nothing in this scenario that matches my situation, I don't have Folder Templates on (you have helped me with that before and I decided to be safe rather than sorry and disabled that for good. My TemplateTest7 is containing only a simple "hello world" , no new note creation command. The only thing I this that is true for me is that I have activate templates on new note creation on.

Archie-2021 avatar Jun 15 '22 06:06 Archie-2021

The Alt + N Templater: Create new note from template basically creates a new file automatically and then you select the template to be added in. (The request for this function originated here #73). It's use is for far more simpler purposes than what we are doing now.

When you said that an Untitled note was created, this is the first thing I thought of. See #649. But it sounds like this is not your problem.


Hmm, then I am sorry. I don't have any additional thoughts on this matter with the information given.

Could you perhaps create a video of your issue? Or list all the other plugins that you are using?

welpdx avatar Jun 16 '22 01:06 welpdx

The Alt + N Templater: Create new note from template basically creates a new file automatically and then you select the template to be added in. (The request for this function originated here #73). It's use is for far more simpler purposes than what we are doing now.

When you said that an Untitled note was created, this is the first thing I thought of. See #649. But it sounds like this is not your problem.

Hmm, then I am sorry. I don't have any additional thoughts on this matter with the information given.

Could you perhaps create a video of your issue? Or list all the other plugins that you are using?

Thank you for your help, I will do that in the future. The problem is still there but my workflow is functional again so I can do it in due time later, number of plugins I use is 100+ (a lot of them are tiny minor adjustments of course). So it takes sometime to do that.

Archie-2021 avatar Jun 16 '22 07:06 Archie-2021

👌

welpdx avatar Jun 17 '22 00:06 welpdx