If statement based on note content in Templater

What I’m trying to do

I’m currently working on a character sheet template set using Templater and I’m trying to get it to dynamically set the contents of a template based on what the note already has in it. The most basic example I’m trying to do is have it adjust to say “he” if the character’s a male and “she” if the character is female.

Things I have tried

I’ve tried a few variations of this:

<%*if(await tp.file.content.match("female")){%> <%"does she"%> <%*}else if(await tp.file.content.match("male")){%> <%"does he"%> <%*} %>

For whatever reason always sets the string to “does she” even if I have the word “male” set already. What am I doing wrong here?

You have to use something like this :

<%*
let content = await tp.file.content;
if (content.match("female")) {
	tR += "does she"
}
else if (content.match("male")) {
	tR += "does he"
}
%>

The tR += insert the content at the cursor.

Thank you it worked perfectly!

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