Hi everyone. I’m trying to use templater to create an automatic link to the local folder that the note is in.
To clarify, I mean one of those links to show the file in the system explorer such as: [The name of the folder](file:///C:%5CUsers%5Cblahblahblah%File%Folder)
Things I have tried
I was asking on Discord and someone sent me this which will create a link to the .md file:
<%*
// Get the TFile of the note to which the template is applied
const file = tp.config.target_file;
const absoluteLink = app.vault.adapter.getFilePath(file.path);
-%>
<% absoluteLink %>
So I’ve been thinking about this and I’m really close to making this work. Chat GPT helped me (lol)
Currently the code is:
<%*
// Get the TFile of the note to which the template is applied
const file = tp.config.target_file;
const filePath = file.path;
const lastIndex = filePath.lastIndexOf('/');
const directoryPath = filePath.substring(0, lastIndex);
const absoluteLink = `${window.location.origin}/#path=${encodeURIComponent(directoryPath)}`;
-%>
<% absoluteLink %>
Basically, it:
gets the file path using the tp.config.target_file thing
Then cuts off the file name, so the link only goes to the folder
But I’m not quite sure how to make it show up as the “absolute link”
(Although there is probably a nicer way to make this happen. lol)
Local folder: [Find the local folder here](file:///C:THISISTHELINKTOTHEVAULTHERE<%*
// Get the TFile of the note to which the template is applied
const file = tp.config.target_file;
const filePath = file.path;
const lastIndex = filePath.lastIndexOf('/');
const directoryPath = filePath.substring(0, lastIndex);
const absoluteLink = `${encodeURIComponent(directoryPath)}`;
-%><% absoluteLink %>)
Anyways, sharing in case anyone else has similar needs.