What is Templater plugin's syntax / language?

I am having a hard time figuring out the syntax. It’s not explicitely mentioned in the docs at all and its driving me mental. Is there an overview of how to use anything besides functions?

What I’m trying to do

I simply want to code more complex templates than simply printing out a piece of data.
Currently my example is to simply check if the file has a property set up yet (is property null?) and then I want to add that property if it doesnt exist with the current date as value.

I have so many questions.
I don’t even know what the correct syntax for if statements are.
Are there loops?
Does it know types and can i save stuff in variables?
Does it use null?

Things I have tried

The doc said to get the properties over the frontmatter library. In the example it shows you can use a “map” func if the property is an array. Where does that come from? Is it merely javascript?

<% if (tp.frontmatter["end-time"] == "undefined") { %>End date exists<% } else { %>End date doesnt exist<% } %>

Does not work. I used “undefined” because that’s what was being printed for my (non existent) property. Null didn’t work either.

Thank you for any hints!

It’s a custom templating engine, similar to eta.

Your fundamental problem is that you can’t do javascript expressions in an interpolation command, which is what you shared. You need to use a javascript execution command, which basically means having an * after the opening <%, like so: <%*.

And yes, the code in these is just javascript paired with templater functions and variables.

See: Execution Commands - Templater and the rest of the docs.

1 Like

Thank you so much!! I skimmed through 90% of this documentation several times, how did I miss this?
I got some of it to work, but I still could not figure out to change the file properties. Maybe that’s just not an option.

You’re welcome. You can definitely change properties, though. See this example by @Zachatoo: Templater snippets

2 Likes