My Zotero annotation template that works

I have made some tweaks to group and name annotations groups with the help of AI. See below for example.

---
{% if title %}Title: "{{title}}"{% endif %}
Authors: {{authors}}{{directors}}
{% if publicationTitle %}Publication: "{{publicationTitle}}"{% endif %}
{% if date %}Date: {{date | format("YYYY-MM-DD")}}{% endif %}
citekey: {{citekey}}
tags: {{hashTags}}
---
## {{title}}
Bibliography : {{bibliography}}
Link to publication : {{url}}
Link Zotero : {{pdfZoteroLink}}
Zotero Tags : {{hashTags}} 
>[!abstract]+
>« {{abstractNote}} »

{% set colorMappings = {

    "#5fb236": "Essential information (Green)",
    
    "#2ea8e5": "Unassigned color category (Blue)",

    "#aaaaaa": "Follow up references (Grey)",
    
    "#ff6666": "Author challenge / Disagreement (Red)",
      
    "#a28ae5": "Definition (Purple)",
     
    "#ffd400": "Highlight (Yellow)",

    "#e56eee": "Personal take (Magenta)",
      
    "#f19837": "Futher reading on concept (Orange)"

} %}

{% for color, calloutName in colorMappings %}
## <span style="color:{{color}}">{{calloutName}}</span>
{% for annotation in annotations %}
{% if annotation.color == color %}
>[!{{calloutName}}|{{annotation.color}}]+ 
>{%- if annotation.annotatedText -%}« {{annotation.annotatedText}} »([{{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 %}
{% endif %}
{% endfor %}
{% endfor %}

  • Removed the colour from the headers, as html span tags were used. However the tags didn’t render in Reading view if headers were used as internal links, and appeared as part of the header name.
  • Added coloured emojis instead. Placed at the end of the header, as at the start makes internal header links more difficult to work with.

-Removed nunjuck white space in editing view.

---
{% if title %}Title: "{{title}}"{% endif %}
Authors: {{authors}}{{directors}}
{% if publicationTitle %}Publication: "{{publicationTitle}}"{% endif %}
{% if date %}Date: {{date | format("YYYY-MM-DD")}}{% endif %}
citekey: {{citekey}}
tags: {{hashTags}}
---
## {{title}}
Bibliography : {{bibliography}}

Link to publication : {{url}}

Link Zotero : {{pdfZoteroLink}}

Zotero Tags : {{hashTags}} 
>[!abstract]+
>« {{abstractNote}} »

{%- set colorMappings = {
    "#a28ae5": "Definition 🟪 ",
    "#ffd400": "Highlight 🟨",
    "#ff6666": "Author challenge / Disagreement 🟥",
    "#e56eee": "Personal take 🧠 ",
    "#f19837": "Further reading on concept 🟧 ",
    "#5fb236": "Essential information 🟩 ",
    "#aaaaaa": "Follow up references ⬜ ",
    "#2ea8e5": "Unassigned colour category 🟦"
} -%}
{%- for color, calloutName in colorMappings -%}
{%- set hasAnnotations = false -%}
{%- for annotation in annotations -%}
{%- if annotation.color == color -%}
{%- set hasAnnotations = true -%}
{%- endif -%}
{% endfor %}
{% if hasAnnotations -%}
## {{calloutName}}
{%- for annotation in annotations -%}
{% if annotation.color == color %}
>[!{{calloutName}}|{{annotation.color}}]+ 
>{% if annotation.annotatedText %}« {{annotation.annotatedText}} »([{{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}}**_»([{{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}&annotation={{annotation.id}})){% endif %}
{% endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}

1 Like

Hey, I have many PDFs with chapter sections. In PDF Expert I can export my annotations to markdown and it treats those section headings as markdown headings. Example:

# Riepilogo note di Guichard 2012 – Eau et société dans l’islam occidental.pdf.
#### Introduction
 *Sottolinea [pagina 2]:* Les musulmans ont en effet entretenu avec l’eau un rapport conditionné par des faits qui tiennent à la fois à la civilisation arabe originelle, aux règles religieuses édictées par le Prophète, et au milieu géographique où s’est développée la nouvelle civilisation.

 *Sottolinea [pagina 2]:* Dans la pratique même de l’islam, la grande importance donnée à la pureté rituelle faisait de l’eau un élément volontiers considéré comme presque indispensable à l’exercice même des obligations religieuses.

#### Le thème de l’eau dans la littérature
 *Sottolinea [pagina 3]:* une énumération et analyse des vocables liés à l’eau à laquelle s’est livrée Francisco Vidal Castro.

Is there any way to have something similar with Zotero and Obsidian? How can I account for that in my Zotero Integration template?

hey all! I have a question:
in Zotero I do not use highlights of different colors, instead I tag my highlights.
in Obsidian I would like to get my annotation grouped by tag rather than color (for example all the annotation / highlights tagged “questions” should have “questions” as group title and then be one after the other under that).

Any help is appreciated, I am not able to find a solution or an already existing template..

I think you could use @Feralflora template (link here) and adapt the line {%- set grouped_annotations = annotations | groupby("color") -%} with color replaced by tag. The main drawback is that it’s not an easy template to begin with.
Hopefully this helps even if tests would probably be required.

1 Like