Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include {{file}} in variables #242

Open
ushham opened this issue Jul 18, 2023 · 5 comments
Open

Include {{file}} in variables #242

ushham opened this issue Jul 18, 2023 · 5 comments

Comments

@ushham
Copy link

ushham commented Jul 18, 2023

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.

@orionpilot
Copy link

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).

@ushham
Copy link
Author

ushham commented Jul 25, 2023

Thank you, that is super useful

@juan11iguel
Copy link

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!

@orionpilot
Copy link

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.

@juan11iguel
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants