Zotero Integration – Import Templates?

Hi Merber,

Under settings > community plugins > Zotero Integration you can specify the template to use (the ‘template file’ dropdown, under the ‘Import Template’ heading).

Does that help or is your issue that Obsidian will still continue using your previous template?

Note that your template is applied only when you import literature; it’s not updated live. So after changing the template, you’ll have to re-import that literature item. Make sure to save any notes/edits made in Obsidian; only those notes wrapped in a nunjucks persist-block will be retained.

@merber There is a way to preview templates without running an import for each, and it’s arguably the best way to go about it. First, you either set up an import format for each template you want to test, or alternatively, you dedicate an import format for testing purposes (I do this with an import format I named “Testing ground”).

Then, rather than actually importing a literature note, you open the Data explorer provided by Zotero Integration using the command palette. Then, you use the template preview feature of Data explorer by selecting the template name from the dropdown, and then selecting the Zotero item to preview.

This gives you a preview of the resulting literature note, which updates as you make changes to the chosen template.

1 Like

I tried the preview function but struggle with two things:

  1. Putting related in frontmatter won´t make links to related papers (eg. [[@citekey]] whithout the link showing green)… Any workarounds? Works in-line.
  2. When importing tags in frontmatter, it shows as “tag”, “tag” etc., not as individual labels (list in properties). I have tried to select a different property type without success.

Here is my template:

---
created: 
updated: 
tags:
  - 📄
aliases:
  - "{{title | escape}}"
keywords: "{% if allTags %}{{allTags}}{% endif %}"
related: "{% for r in relations %} [[{{r.citekey}}]]{% if not loop.last %}, {% endif %} {% endfor %}"
authors: "{{authors}}{{directors}}"
year: '{{date | format("YYYY")}}'
citekey: "[[@{{citekey}}]]"
title: "{{title}}"
itemtype: "{{itemType}}"
journal: "{{publicationTitle}}{{publisher}}"
pages: "{{pages}}"
course: 
lecture: 
reccomended: 
status: 🟩
rating:
---
# {{title}}
- Summary:: 
- Zotero:: {{pdfZoteroLink}}
- Abstract:: {{abstractNote}}
# Highlights
{% for annotation in annotations -%} 
{%- if annotation.annotatedText -%} 
- {{annotation.annotatedText}}” [Page {{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}&annotation={{annotation.id}}) 
{%- endif %} 
{%- if annotation.imageRelativePath -%}
![[{{annotation.imageRelativePath}}]]{%- endif %} 
{% if annotation.comment %} 
	- {{annotation.comment}} 
{% endif %} 
{% endfor -%}
# Notes

And output:

Thanks :))

You shouldn’t comma separate them, but put them as bullets into the properties.

This is what I do for tags:

tags:{% for t in tags %}
- {{t.tag | replace(r/\s+/g, "-")}}{% endfor %}

And you could do the same for related:

related:{% for r in relations %}
- [[{{r.citekey}}]]{% endfor %}

Thank you very much @Feralflora and @tidebo for your replies! Very helpful! Sorry I didn’t get notifications so didn’t realize you had replied.

I haven’t been able to properly test either previews or adding a new template however, as I seem to be having a bigger problem with my templates now. They are not called up at all for either templater or templates.

I have two vaults. In the first vault that I was asking about, the message when I try to pull up a template that worked before is “Error retrieving item data. Unexpected end of JSON input.” No templates are listed.

In my second vault (which is a vault that someone else created and I just downloaded from Github), when I try to pull up a template via the Core template plugin, I get the error message "Failed to list templates: folder "meta/templates/ not found

When I try to pull up a templater template I get "Couldn’t retrieve templates file from templates folder “meta/templater”. Check console for more info. "

The templates worked fine yesterday. I did move the original folders from my desktop on iCloud to Google Drive, yesterday, however, so I am wondering if that has something to do with it. I am afraid to do any work in Obsidian, as I am wondering if many other links are broken now too. The “daily note” is still working.

It’s a better bibtex issue:

I believe you can just update Zotero Integration to have a fix for the issue.

Hi thanks! I updated plugins for both vaults. It solved the problem for the vault with the JSON message, but the other one with the other notes it did not. For the regular template, I get the error message "Failed to list templates: folder ‘meta/templates/ not found.’ And for the templater template I get "Couldn’t retrieve templates file from templates folder, ‘meta/templater.’ Check console for more info. " Any idea what might be causing this?

I’m not sure what Templater or Templates (core) have to with this thread? This is about templates for Zotero Integration, which don’t Templater or Templates, unless you have some Templater code included in the ZI template.

This sounds more like general templating issues.

For such issues, you should post separate topics in the help section of the forum.

Wonderful! The first one worked perfectly. Still having issues with related though. When putting a @ in front of r.citekey:

related: {% for r in relations %} 
- [[@{{r.citekey}}]]{% endfor %}

…I get invalid properties:

without @, properties work, but it displays like this:

Any suggestions?

This is awesome, thank you. I noticed that whenever I import my annotations to Obsidian, it duplicates them for some reason. What am I doing wrong? I am new to this, so I apologise for being stupid, lol. It is quite overwhelming, though.

I think the links just need quotes, like so:

related:{% for r in relations %}
- "[[@{{r.citekey}}]]"{% endfor %}

Ah nice! Sorry for newbie questions, but I now get a JSON error:
image

Frontmatter is:

created: 
updated: 
tags:
- 📄
aliases:
- "{{title | escape}}"
keywords: {% for t in tags %}
- {{t.tag | replace(r/\s+/g, "-")}}{% endfor %}
related: {% for r in relations %} 
- "[[@{{r.citekey}}]]"{% endfor %}
authors: "{{authors}}{{directors}}"
year: '{{date | format("YYYY")}}'
citekey: "[[@{{citekey}}]]"
title: "{{title}}"
itemtype: "{{itemType}}"
journal: "{{publicationTitle}}{{publisher}}"
DOI: "{{DOI}}"
pages: "{{pages}}"
course: 
lecture: 
reccomended: 
status: 🟩
rating:
---

Any thoughts?

Yes, see this: Zotero Integration – Import Templates? - #271 by Feralflora

Just update Zotero Integration.

Wonderful! Thanks so so much

Hi again! Is there a way to link to the Zotero Item, not the attachment pdf? Say if you have added a book without a pdf attachment and want to jump to the item in Zotero :))

Also, sharing my final template for academic papers here:

---
created: 
updated: 
tags:
- 📁/📖/🟩
aliases:
- "{{title | escape}}"
course: 
lecture: 
reccomended: 
rating:
related: {% for r in relations %} 
- "[[@{{r.citekey}}]]"{% endfor %}
keywords: {% for t in tags %}
- {{t.tag | replace(r/\s+/g, "-")}}{% endfor %}
authors: [{% for a in creators %}{{a.firstName}} {{a.lastName}}{% if not loop.last %}, {% endif %} {% endfor %}]
year: '{{date | format("YYYY")}}'
citekey: "[[@{{citekey}}]]"
title: "{{title}}"
itemtype: "{{itemType}}"
journal: "{{publicationTitle}}{{publisher}}"
ISBN: {{ISBN}}
pages: {{pages}}
---
## {{title}}
- Summary:: 
- Zotero:: {{pdfZoteroLink}}
- Abstract:: {{abstractNote}}
## Highlights
{% for annotation in annotations -%} 
{%- if annotation.annotatedText -%} 
- {{annotation.annotatedText}}” [Page {{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}&annotation={{annotation.id}}) 
{%- endif %} 
{%- if annotation.imageRelativePath -%}
![[{{annotation.imageRelativePath}}]]{%- endif %} 
{% if annotation.comment %} 
	- {{annotation.comment}} 
{% endif %} 
{% endfor %}
## Notes

Thank you very very much for all the work you’ve put into developing and sharing this! As someone who is totally new to Obsidian, markdown, and nunjucks this was a lifesaver! I only have one question, which is probably quite a silly one, but here goes:
How do you change the icons in the headers? My annotation categories are slightly different from yours and it would be great to swap out a couple of the icons but I can’t for the life of me figure this out. Assuming it’s something quite basic but it’s beyond me. Thanks again!

Hi @sea-palm, glad you found my template useful!

Sorry for the delay in getting back. Hopefully, you’ve solved this by now.
Otherwise, you should just edit the headers in the colorValueMap variable of the latest edition of the template. In the old version you replied to, it’s just in the heading(color) macro.

1 Like

Thanks so much!

1 Like

Thank you for pointing. But it is still not clear what one should configure in the hotkeys settings?

Are you trying to set up the update button? That’s what the message you replied to is referring to. Feel free to DM me, if you need help with that.