What I’m trying to do
I am trying to find a way I can future-proof links to my personal media files stored (currently) on my NAS storage so that i can reference them/embed them into my notes. This way, if in the future I find myself having to move the media file directory to another service or location I can just update the root path in one place and still have my obsidian vault finding my files.
Things I have tried
I have tried creating a “global variable” (in this example, stored in a file in my vault “+GlobalVars+”):
I’m able to successfully access and append this to create the file path to a file, for example:
However, what I’m trying to do in order to embed the file doesn’t work but also is very clunky to do long-term. Does anyone have a better way of achieving this? Below is what I’ve been trying with:
=[[+GlobalVars+]].media_root + "/2016-03/2016-03-01/100.JPG"]]
As way of an update, I’ve found “something” that gets me a step closer - in that I can access medial files outside of my Obsidian Vault:
[Test link to local files](<file:////Volumes/MyExternalHD/MyFolder/2023/2023-01/2023-01-01/MyPhoto.jpg>)
However, I can not see a way to generalise it with my
I think your best bet is to user a
dv.view() function to generate the link, and then that script could have the media root hard coded.
You could then do stuff like:
`= dv.view("js/medialink", ["link description", "media/file.png"]) `
Do however be aware that embedding is a little clunky in any solution.
If you’re only using reading view, and not live preview, you could also consider using Templater user functions, for a slightly leaner function call, like:
<%+ tp.user.medialink("link description", "media/file.png") %>