Templater plugin: Subfolders autogenerate as tags

I’m trying to use Templater to auto-generate tags based on the relative file path of each note. For instance, if a note is in the “media” folder, I want it to cough up the tag #media.

So far I’ve used this code, and it works just fine for one such folder-to-tag:

#<% tp.file.folder()
.split(' ').join('_')%>

However, what I want is something different. I want to show the FULL path, with each subfolder outputted as a tag.

i.e., if my note is in the directory “media/print/books”, I want my code to generate a tag that looks like: #media/print/books.

Does that make sense? Thanks!

You could use tp.file.find_tfile("note title") which will return a TFile object that has a path with the full path to the note. You need to remove the file at the end of the path.

#<%
tp.file.find_tfile(tp.file.title).path.replace(`/${tp.file.title}.md`,'')
%>

Something like that.

1 Like

We have a winner! Thank you!

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