Dynamic local links to set a new base path

What I’m trying to do

I’m fairly new to Obsidian and all its advanced features, so I apologize if what I write is unclear or incomplete.

I’m trying to find a way to pass and concatenate a simple variable to a local link path, kinda like this:

basepath = C:\Uni
[Lesson1](file:/// + basepath + \Math\Lesson1.pdf)
[Lesson2](file:/// + basepath + \Math\Lesson2.pdf)

My original objective was to use OS Environment Variables to dynamically build links, using the environment variable as base path, concatenate a relative path to its subfiles and subfolders, and be able to open the correct path everytime the base path is updated.
This way I can move all my Uni files (or easily migrate to a new machine) and only update a single variable line in Obsidian responsible for the base path.

Having done some research now I know Obsidian doesn’t support environment variables, but replacing that with a single local variable within Obsidian would still be great.

Things I have tried

Moving my notes to the Uni folder is definitely something I don’t want to do.

I already tried using Dataview and YAML but any variable inserted in the parenthesis will only be seen as a string and not be replaced with its value. Maybe I’m missing something? example:

link:: file:///C:\Uni\Math\
MathFolder ← will be seen as a note link and create a new note titled " =this.link "

I tried Shell Commands and tried to make it work through shell, but either it’s outside the scope of the plugin or I’m not knowledgeable enough about Obsidian and Shell to make it work properly (probably both).

I also tried 2 text expanders but both didn’t seem to work properly at all.

In respect of the inline link …

Wrapping the LINK in straight quote marks appears to work. Is this in part what you are trying to achieve?

---
LINK: "[File Title](file:///Users/path/filename.pdf)"
TAGS: testfiles
---
`=this.link` 

… parses as File Title.

EDIT: That’s with a file, not a folder. Forgot to test links to folders.

Thanks for the reply.
It’s still not what I’m looking for. It does parse and link correctly yes, but it’s only a static link to a single file.
It works if you want to use a single variable for a single path, but I want to use that variable as a simple string to reuse multiple times in different links.

---
LINK: "C:/Users/reusable_path"
---
[File Title](file:///`=this.link`\filename.pdf)

but =this.link doesn’t display its value when inside the path, it’s just seen as a string.

Topic

Summary
  • How to concatenate the value of a field to a local link path under windows operating system?

Test

Summary
  • dataview: v0.5.46

input

Summary

the current note

  • filename : 20220927_Q85_inDQL10
---
LINK: "C:/Users/reusable_path"
---

### inDQL10




dictionary files

  • filename : filename.pdf
    • Location: “file:///C:/Users/reusable_path/Math/filename.pdf”

inDQL10_concatenate_a_field_to_a_local_link_path

Summary

inDQL10_concatenate_a_field_to_a_local_link_path

Summary_code
---
LINK: "C:/Users/reusable_path"
---

### inDQL10
local link=`="[File Title](file:///" + this.LINK + "/Math/filename.pdf)"`


Screenshots(inDQL10)

Part 1/2

Part 2/2


1 Like

YES! This is it.
I’d kiss you on the forehead if it weren’t for the screens separating us. Thank you very much.

Next I’ll try to find a way to read environment variables from the OS and automatically assign them to some variables to completely automate re-linking everytime I migrate device. I’m considering writing my own plugin but that won’t see the light of day anytime soon.

1 Like

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