Templater says that my tp.file is undefined

What I’m trying to do

It’s kind of very simple. When I try to call tp.file.title it says that it can’t read the property file because it is undefined. The context of this is, I’m trying to access the tp.file from a user script. My Templater is already set up. Templater does detect my custom “function”/script. But whenever I write in my note <%* await tp.user.load_function() %> and then hit the Command Palette → “Templater: Replace templates in the active file” I get this error:

Templater Error: Template parsing error, aborting.
Cannot read properties of undefined (reading ‘file’)

I’ve already searched on this topic but nothing similar has come up. I tried debugging with ChatGpt. I’ve made sure that Templater has the correct scripts folder and templates folder. It seems like a very weird error since tp.file is very fundamental to Templater but it seems that even though I call it from a note it says the file is undefined.

Can someone help me please?

If you’re trying to read the tp or file object in a user_function you should give it as an argument to that function. As in the documentation: “However, you can’t access the template engine scoped variables like tp or tR . If you want to use them, you must pass them as arguments for your function.” User Scripts - Templater

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