Help with Templater and Buttons

I wonder if some Templater experts wouldn’t mind casting an eye at this:
I am trying to create some buttons as default at the top of my documents. Simply they would move the current file to a certain existing folder. I am very new at this so using some chat GPT for help. It looks correct, looking at the docs for Templater. Perhaps the issue is the buttons don’t allow execution of the code ?

Any pointers appreciated.
Thanks
A

<%*
function moveFile(folder) {
    let currentFilePath = tp.file.path;
    let newFilePath = tp.file.folder + "/" + folder + "/" + tp.file.name;
    tp.file.move(newFilePath);  // Moves the file to the new folder
}
%>

<button onclick="moveFile('Work')">Alan</button>
<button onclick="moveFile('Fun')">Eddie</button>
<button onclick="moveFile('Projects')">Tom</button>

The Auto Note Move Plugin could be a better solution. You add a tag and it auto moves the file for you based on rules you define.

This would combine well with the Meta Bind Plugin where you can bind YAML and commands with buttons and input fields.

You could make a Meta Bind Button then Under Actions, choose command and set it to `file-explorer:move-file

QuickAdd Macro could also work. Bind the macro to the Command Palette then use meta bind button to call it.

If you did it with templater it might get a little messy as you have to capture insert the templater script then execute the code.

1 Like

Thank you Paul,
I watched you excellent vid on Meta-Bind and have made buttons across the top of my default document, that essentially folderize the current note.

The buttons add say #workflow and then the Auto Notes mover plugin picks up on that and folderizes the note in the correct place. Personally, it’s exactly what I want.

Thanks again.

ps. that could be a use case for the JS option in Meta-Bind buttons but I don’t really need it with the other plugin doing its job.
image

1 Like