Open ushham opened 1 year ago
Since file
is an entry in the bibtex file, you can access it using {{entry.data.fields.file}}
in the template. This is based on #100, which is how you can get other entries from the bibtex in the template if they do not have a shortcut built-in (the list in the plugin settings).
Thank you, that is super useful
One issue is that the path string is not URL encoded, I would like to automatically preview the pdf inside the note if it exits, however, for example, when using {{entry.data.fields.file}}
I get:
/home/jmserrano/Zotero/storage/65S2H5BM/Al-Hotmani et al. - 2020 - Scope and Limitations of the Mathematical Models D.pdf
Instead of something like this:
/home/jmserrano/Zotero/storage/65S2H5BM/Al-Hotmani%20et%20al.%20-%202020%20-%20Scope%20and%20Limitations%20of%20the%20Mathematical%20Models%20D.pdf
Also it would be great to not use an absolute path, since opening this note would break in a different machine. I am not sure how this could be implemented, maybe to allow an environment variable ZOTERO_STORAGE_PATH
or something along those lines.
BTW, great work on the plugin!
I ended up writing my own javascript module to get the file link URL encoded. When the template runs, it runs this custom templater script. I don't have the same absolute path problem (for now) since my machines have the same user (blame Microsoft account), so I don't think my script would work for you. But the idea is to search the folder where the PDFs are located, find the one with the same name as the template you're generating, find and replace spaces for %20
, and return that new filename.
In the citations template it looks lile: [PDF](file:///<% tp.user.pdflink(tp) %>)
where pdflink
is my custom script. Clicking that opens the file if it exists. Haven't added an exception in case the PDF does not exist yet.
That looks very promising, I guess in that custom script a more extensive encoding could be applied to make it more robust (not just spaces)
I need a link to the location of the PDF in my local file structure. I would like the variable {{file}} to be included in the template.
This variable exists in my .bib file, I would like to be able to include it in my obsidian template.