buttons icon indicating copy to clipboard operation
buttons copied to clipboard

Feature request: Have templater buttons that just run the template (without prepending o appending)

Open fidel-perez opened this issue 3 years ago • 3 comments

It would be great to have also a button that only runs a template.

Why? Because then we could run templates like the following to, for example (in the code below), replace all the checked boxes for unchecked ones, without adding any text to the note:

<%*

//get file content and replace checked boxes for unchecked
var noteContent = tp.file.content.replaceAll ("[x]","[ ]");

//select all in note
let cmEditorAct = this.app.workspace.activeLeaf.view.editor;
cmEditorAct.setSelection({ line: 0, ch: 0 }, { line: 9999, ch: 9999 });

//replace content + set cursor at the start
cursor = tp.file.cursor(0);
tR = cursor + noteContent.split("<%*")[0];

%>

Right now I do the trick of using append then removing that appended text: noteContent.split("<%*")[0] But this works randomly depending on some speed of an internal process that appends the templater text to the note (because thats the button I am using).

This works perfectly when applying the template using templater command, but with buttons we cannot replicate because of the extra text insertion.

This feature would allow us to run any javascript to modify the current note using templater, I think it would be pretty cool :)

Thank you!

fidel-perez avatar Sep 14 '21 22:09 fidel-perez

Really good idea that should be pretty easy to do. Will look into it.

shabegom avatar Sep 22 '21 18:09 shabegom

+1 to this. I would like to use this to have pass Templater an argument from the current file that it uses to create a new file.

paulrudy avatar Dec 15 '21 07:12 paulrudy

has this been implemented?

DeutscheGabanna avatar Jul 09 '22 22:07 DeutscheGabanna

  • 1

simzdk avatar Nov 10 '22 09:11 simzdk