Zotero Integration – Import Templates?

It is, it should be like this:

zotero://open-pdf/library/items/{{annot.attachment.itemKey}}?page={{annot.pageLabel}}&annotation={{annot.id}}

The annotation ID was missing, and annot.page should be annot.pageLabel.

This solved the issue for me!

I appreciate the update. I was wondering if there is a way to do an underscore instead of a hyphen? I have any of the tags I add to my comments in Zotero importing with an underscore using

Tag: {% for annotation in annotations -%} {% if annotation.tags %} {% for t in annotation.tags %} #{{t.tag | replace(" ", “_”)}}{% if not loop.last %}, {% endif %} {% endfor %} {% endif -%} {% endfor -%}

but this only modifies the tags I add to highlight notes. The actual paper keywords are imported with a hyphen which for my case can be an issue give terms like “three-phase power” or “grid-tied inverter”.

Yeah, sure, just use an underscore where I put a hyphen. Replace the code in your frontmatter with my code example, with the underscore included.

That worked but I am not sure what I am missing.

Tag: {% for annotation in annotations -%} {% if annotation.tags %} {% for t in annotation.tags %} #{{t.tag | replace(" ", “_”)}}{% if not loop.last %}, {% endif %} {% endfor %} {% endif -%} {% endfor -%}

In the above where I have replace (" ", "\_") looks the same as yours, and is what I used to make that change. Is it because I have annotation.tags which is not looking at the Tags imported as metadata in the image?

image

Either way, thanks. Saved me from having to update every tag in Zotero to make it work.

Hey guys I found this template somewhere and currently it splits the highlights based on colour into different sections but I would like so each sections heading has the background colour of my chosen highlighter plugin colour is anyone able to help?

# {{title}}

## Index

> [!info] Info – {% for attachment in attachments | filterby("path", "endswith", ".pdf") %}[PDF{% if not loop.first %} {{loop.index}}{% endif %}]({{attachment.desktopURI|replace("/select/", "/open-pdf/")}}){% if not loop.last %}, {% endif %}{% endfor %}
> {{bibliography}}
> 
> - Date: ({{date | format ("DD/MM/YYYY")}})
> - Zotero: [See in Zotero]({{select}}){% if relations %}{% endif %}

> [!example] Abstract
> *{{abstractNote | nl2br}}*

{#- WARNING: Everything below this line will get overwritten on re-import! -#}
{#- COLOR VARIABLES -#}
{%-
    set zoteroColors = {
        "#2ea8e5": "blue",
        "#5fb236": "green",
        "#a28ae5": "purple",
        "#ffd400": "yellow",
        "#ff6666": "red",
        "#f19837": "orange",
        "#e56eee": "magenta",
        "#aaaaaa": "grey"
    }
-%}

{%-
   set colorHeading = {
        "blue": "⭐ Main",
        "green": "Questions",
        "purple": "🧩 Methodology",
        "yellow": "Main Point",
        "red": "Quotes",
        "magenta": "📎 Info",
        "grey": "Definitions"
   }
-%}

{#- ANNOTATION TYPES -#}
{%- macro calloutHeader(type) -%}
    {%- switch type -%}
        {%- case "highlight" -%}
        Highlight
        {%- case "image" -%}
        Image
        {%- default -%}
        Note
    {%- endswitch -%}
{%- endmacro %}

{#- SET CUSTOM ANNOTATION COLORS -#}
{%- set newAnnot = [] -%}
{%- set newAnnotations = [] -%}
{%- set annotations = annotations | filterby("date", "dateafter", lastImportDate) %}

{% if annotations.length > 0 %}*Imported: {{importDate | format("YYYY-MM-DD HH:mm")}}*

{%- for annot in annotations -%}

    {%- if annot.color in zoteroColors -%}
        {%- set customColor = zoteroColors[annot.color] -%}
    {%- elif annot.colorCategory|lower in colorHeading -%}
    	{%- set customColor = annot.colorCategory|lower -%}
    {%- else -%}
	    {%- set customColor = "other" -%}
    {%- endif -%}

    {%- set newAnnotations = (newAnnotations.push({"annotation": annot, "customColor": customColor}), newAnnotations) -%}

{%- endfor -%}

{#- INSERT ANNOTATIONS -#}
{#- Loops through each of the available colors and only inserts matching annotations -#}
{#- This is a workaround for inserting categories in a predefined order (instead of using groupby & the order in which they appear in the PDF) -#}

{%- for color, heading in colorHeading -%}
{%- for entry in newAnnotations | filterby ("customColor", "startswith", color) -%}
{%- set annot = entry.annotation -%}

{%- if entry and loop.first %}

### {{colorHeading[color]}}
{%- endif %}

> [!quote{{"|" + color if color != "other"}}]+ {{calloutHeader(annot.type)}} ([p. {{annot.pageLabel}}](zotero://open-pdf/library/items/{{annot.attachment.itemKey}}?page={{annot.pageLabel}}&annotation={{annot.id}}))

{%- if annot.annotatedText %}
> {% if annot.hashTags %}[[{{annot.hashTags|replace("#", "")}}]]: {% endif -%}
{{annot.annotatedText|nl2br}}
{%- endif %}

{%- if annot.imageRelativePath %}
> ![[{{annot.imageRelativePath}}]]
{%- endif %}

{%- if annot.ocrText %}
> {{annot.ocrText}}
{%- endif %}

{%- if annot.comment %}
> → **{{annot.comment|nl2br}}**
{%- endif -%}

{%- endfor -%}
{%- endfor -%}
{% endif -%}

Hi I have a simple question.
I have downloaded a couple of Zotero integration templates to see which one works best for me.
How do I switch between the templates when testing them out?
I uploaded a new template, but my obsidian keeps using the old one.
Thanks!

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.