What I’m trying to do
Is there an easy way to reference a parent folder with Templater?
I have several work projects that I put in nested folders - Client-Project-Note. I’m using Templater to automatically create YAML frontmatter that I can reference later with Dataview.
Folder structure looks something like this:
- Client Folder
- Project Folder
*Note
- Project Folder
In the note, I want to be able to extract both the Client Name and the Project Name separately so I can reference them later in Dataview.
I have no trouble accessing the immediate folder that the note is in, but how do I extract the name of the parent folder?
Things I’ve tried
I’ve seen various references to using Javascript, but that’s not really my area of expertise. I’ve tried to figure it out, but haven’t had any luck so far.
I looked at both of these:
https://forum.obsidian.md/t/templater-get-the-parent-folder-name/47241
https://forum.obsidian.md/t/templater-and-obsidian-api-list-parent-folders-as-internal-links-in-note/26349/2
But clearly I’m missing something about the Javascript. Can I put that inline into my Templater note? Or does the Javascript go elsewhere?
I tried installing the CustomJS plugin, but can’t get that to work.
I also tried using the file path but can’t figure out how to get just the folder name I’m looking for and not the full file path. Slice is great, but the length of the text strings is different. Unless there’s a way I can tell Templater to drop everything after the second / ?
Or is there a better way to get at this with Dataview?
I’m a sound engineer, so I try to do as much as I can, but I’m clearly not a coder…