Why is my template giving me an error?

Things I have tried

I made a template file and put this code in it

#_Created at 2022-03-19
Aliases: "<% tp.file.title %>"
#Thailand  #Language_Learning #thai/language 

<%	await(tp.file.rename("Thai Study Block "+ tp.date.now())) %>

# Thai Study session for <% tp.date.now() %>
## notes 
- I want to make this calendar-clickable.  
### Want to do, but not enough time:

I use the URL obsidian://advanced-uri?vault=wealthyvault&filepath=Projects/Thai%20Language/Study%20Blocks/Untitled.md&mode=overwrite to try to do what I want. Whether I use mode=new or mode=overwrite, I get the same error:


When I look in my vault, I see that it created TWO files, one called “Untitled” and one with the title (and contents!) I expect, “Thai Study Block 2022-03-22”


The file seems to get populated with all the right things, but the error message is worrisome and it’s clear I’m not understanding how to use this right. I’m pretty sure this is wrong. I just discovered the Console which helps.

Can someone help me understand how to fix this and why it’s happening?
Thank you.

What I’m trying to do

I’m trying to make is so that when I click on the link in my calendar, it creates a study session in the right folder with the correct date and contents.
I’m trying to use obsidian-url and Templater.
I’m not an obsidian expert and some of this scripting stuff is very arcane. Still learning.

If I watch closely a video of the process, I see that after I click the URI, the Untitled gets created, then renamed, then another Untitled appears again in the file list. I don’t quite understand template parsing yet.

I think I found the answer, sort of.
It apparently was bad to do this in the YAML: Aliases: "<% tp.file.title %>"
Commenting that line out causes the file Template to work correctly.
cheers to all

1 Like

Dang that did ==not fix it==. this morning I tried again and it is still broken.
So I guess I’m back to square one on this. Why is my file being weird?

I also tried removing all spaces from the path as if that was a concern. It did not help.
Another thing is I have the exact same code in another file and it works fine. :stuck_out_tongue:

Still looking for what is different. Here is the whole file now:

<% await(tp.file.rename( tp.date.now("YYYY_MM_DD_")+"Thai_Study")) %>

Yes, that’s the entire body, no YAML, nothing else. No spaces anywhere. Hmm.

I don’t know, but what video were you watching?

Did you insure the file doesn’t already exist?
Does it work in the other file, because it is located in another folder?

1 Like

The file does not exist before it gets created by Templater.
I don’t know how to investigate the other question, but I will test it.

OK I’m having a WTF moment now.
Spurred by your question, I assigned the Thai Template to another folder where I know another template I use is definitely working. And to my surprise, your theory worked: my template worked there!
Huh. So I assigned it back to the Thai Study folder and guess what? It works every time now.
So somehow your idea fixed it! Thank you!
Know I’m just curious what was happening but I can’t reproduce it now.
Another change I made was to reorder my Folder Templates list items and move Thai from bottom to top. But reverting that also does not bring the bug back.
I know I didn’t mistype the folder name or anything, the GUI helps with that.
Huh. Funny computers! PEBCAK?
I’ll mark your answer as the solution tomorrow because it probably is! Cheers.

for Thai study?