shabegom / buttons

Buttons in Obsidian
The Unlicense
478 stars 50 forks source link

Template button does not execute in working directory of the note itself #50

Closed pdxrlk closed 3 years ago

pdxrlk commented 3 years ago

I am trying to create a simple template button which invokes "ls" through a Templater user-defined function:

name files in this directory
type note(Filelist, split) template
action template - ls

And the "template - ls" template is:

<% tp.user.ls({a: tp.file.folder(true)}) %>

And the "ls" user defined function in Templater is merely:

ls "$a"

I expected to get a list of the files in the same directory as the originating note, but I get a list of files in my home directory.

Is there a workaround?

shabegom commented 3 years ago

Power User alert! I'll try and reproduce. I'm assuming the ls templater command works outside of a button?

pdxrlk commented 3 years ago

Hi - yes it works outside of a button. (which reminds me of a dad joke: "outside of a dog, a book is a man's best friend. inside of a dog, it's too dark to read")

shabegom commented 3 years ago

@pdxrlk So I looked into this and if the note you're creating is in the home note directly it lists the files/folders in the base path "/".

If you adjust the button to create the FileList in a folder it will list files in that folder. So the button would be something like:

```button name files in this directory type note(Folder/Filelist, split) template action template - ls ```

This button will create a file that lists all files inside the Folder.