Closed AlbertoEE closed 5 months ago
Okay I will answer myself -> Always return in your javascript function the string with the templater command.
Example:
async function createNewNpc (tp) {
const folder = app.vault.getAbstractFileByPath("Areas/Gaming/D&D/NPCs")
let npcName = await tp.system.prompt("Enter NPC name: ")
let file = await tp.file.create_new(tp.file.find_tfile("NPC"), npcName, false, folder)
let content = await app.vault.read(file)
console.log(content)
return "<%tp.user.createNewNpc(tp)%>"
}
module.exports = createNewNpc;
This is the important part return "<%tp.user.createNewNpc(tp)%>"
.
Here is the code of the button:
button
name Add NPC
<%tp.user.createNewNpc(tp)%>
templater true
This only solves on problem. When you click any button on the page it still executes all templater scripts linked to buttons run.
the code will run the Templater command replace template in note.. and undoes that afterwards. that might be your issue. and I don't know if calling a javascript in that way will work, as you probably need to have await in front of the call of tp.user....
I have 2 buttons on the same note.
When clicking one of them, both are executed, and then the buttons look like this: