Hi everyone, thank you for all the templates in this thread!
I’ve been setting up an Obsidian-Zotero workflow so have been messing around with some of the templates to find something that would work well for me, and I thought I’d share it here as well.
I used this template by Marshall_Tang as a base. In most of the templates that I have seen so far, it looks like there’s an issue when reimporting annotations such that the headings would be created again while being appended to the older text that’s within a persist block. I’ve found a workaround that allows for the new annotations to be appended to its corresponding group below the annotations from the previous import without creating a duplicate heading. I’ve also made it so that if there are no annotations of a particular colour (e.g., Red), then its corresponding heading will not be created during the first import, but if there’s a red annotation in the second import, the heading will be created and the annotation will be placed in the correct group. It also preserves the order of the groups/colours/headings through all imports.
@headswillroll1789 @Feralflora When searching about this issue, I came across this forum post where you were discussing the duplicated headings. I’m not sure if anyone else has shared any template with a workaround, but if not, maybe this could be of use. It was a bit tricky to do considering how the persistent field function works but it seems to be working for me so far. I broke the persist blocks into smaller chunks for each group and used the import dates as a reference to avoid the duplicate headings. If anyone has any suggestions to make the template better, I’d love to hear them!
I’ve shared the template below along with a couple of screenshots. The css snippet I’m using is from Iguenth available in their obsidian-templates repository on GitHub.
---
title: "{{title | escape}}"
authors: {{authors}}
year: {{date | format("YYYY")}}
type: {{itemType}}
journal: {{publicationTitle}}
doi: {{DOI}}
tags: {% if allTags %}{{allTags}}{% endif %}
citekey: {{citekey}}
date added: {{exportDate | format("DD/MM/YYYY")}}
cssclass: literature-note
---
# {{title}}
> [!abstract]-
> {% if abstractNote %}
> {{abstractNote|replace("\n"," ")}}
> {% endif %}
> [!info]- Metadata – {% 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 %}
> **Title**:: {{title}}
> **Authors**:: {%- for creator in creators %} {%- if creator.name == null %} {{creator.firstName}} {{creator.lastName}}, {%- endif -%} {%- if creator.name %}**{{creator.creatorType | capitalize}}**:: {{creator.name}}{%- endif -%}{%- endfor %}
> **Year**:: {{date | format("YYYY")}}
> {%- if itemType %}**ItemType**:: {{itemType}}{%- endif %}
> {%- if itemType == "journalArticle" %}**Journal**:: *{{publicationTitle}}* {%- endif %} {%- if itemType == "bookSection" %}**Book**:: {{publicationTitle}} {%- endif %}
> {% if hashTags %}**Keywords**:: {{hashTags}}{% endif %}
> {%- if DOI %}**DOI**:: {{DOI}}{% endif %}{%- if ISBN %}
> **ISBN**:: {{ISBN}}{% endif %}
> **Related**:: {% for relation in relations -%} {%- if relation.citekey -%} [[{{relation.citekey}}]], {% endif -%} {%- endfor%}
{% persist "notes" %}
{%- if isFirstImport %}
> [!Tldr]- Key Takeaways
> **Research Gap/Qs**:
> **Methodology**:
> **Result**:
> **Contribution**:
> **Limitation**:
{% endif -%}
{%- endpersist %}
## Reading Notes
{%- macro calloutHeader(type) -%}
{%- switch type -%}
{%- case "highlight" -%}
Highlight
{%- case "image" -%}
Figure
{%- default -%}
Note
{%- endswitch -%}
{%- endmacro -%}
{%- set annotAll = [] -%}
{%- set annotAll= annotations | filterby("date", "dateafter", lastImportDate) -%}
{% if annotations.length > 0 %}
*Imported: {{importDate | format("DD/MM/YYYY HH:mm")}}*
{%- set annotOld = [] -%}
{%- set annotOld = annotations | filterby("date", "dateonorbefore", lastImportDate) -%}
{################# Red Annotations #################}
{%- set annotRed = [] -%}
{%- for a in annotAll -%}
{%- if a['colorCategory'] == "Red" -%}
{%- set annotRed = (annotRed.push(a), annotRed) -%}
{%- endif -%}
{%- endfor -%}
{%- set annotRedOld = [] -%}
{%- for a in annotOld -%}
{%- if a['colorCategory'] == "Red" -%}
{%- set annotRedOld = (annotRedOld.push(a), annotRedOld) -%}
{%- endif -%}
{%- endfor -%}
{%- persist "rednotes" -%}
{### Inserts a heading only if there are red annotations in the current import and if there weren't any in previous imports ###}
{%- if annotRed.length > 0 -%}
{% if annotRedOld.length <= 0 %}
### Disagree with / Sceptical of Author
{%- endif -%}
{% endif %}
{% if annotRed.length > 0 %}
{%- for annot in annotRed -%}
> [!quote|red]+ {{ calloutHeader(annot.type) }} ([Page {{ annot.pageLabel }}]({{ annot.desktopURI }}))
{%- if annot.annotatedText %}
> {{annot.annotatedText|nl2br}} {% if annot.hashTags %}{{annot.hashTags}}{% endif -%}
{%- endif %}
{%- if annot.imageRelativePath %}
> ![[{{annot.imageRelativePath}}]]
{%- endif %}
{%- if annot.ocrText %}
> {{annot.ocrText}}
{%- endif %}
{%- if annot.comment %}
> - **{{annot.comment|nl2br}}**
{%- endif %}
{% endfor %}
{%- endif %}
{%- endpersist -%}
{############## Yellow Annotations ##############}
{%- set annotYellow = [] -%}
{%- for a in annotAll -%}
{%- if a['colorCategory'] == "Yellow" -%}
{%- set annotYellow = (annotYellow.push(a), annotYellow) -%}
{%- endif -%}
{%- endfor -%}
{%- set annotYellowOld = [] -%}
{%- for a in annotOld -%}
{%- if a['colorCategory'] == "Yellow" -%}
{%- set annotYellowOld = (annotYellowOld.push(a), annotYellowOld) -%}
{%- endif -%}
{%- endfor -%}
{%- persist "yellownotes" -%}
{%- if annotYellow.length > 0 -%}
{% if annotYellowOld.length <= 0 %}
### Important / Interesting Point by Author
{%- endif -%}
{% endif %}
{% if annotYellow.length > 0 %}
{%- for annot in annotYellow -%}
> [!quote|yellow]+ {{ calloutHeader(annot.type) }} ([Page {{ annot.pageLabel }}]({{ annot.desktopURI }}))
{%- if annot.annotatedText %}
> {{annot.annotatedText|nl2br}} {% if annot.hashTags %}{{annot.hashTags}}{% endif -%}
{%- endif %}
{%- if annot.imageRelativePath %}
> ![[{{annot.imageRelativePath}}]]
{%- endif %}
{%- if annot.ocrText %}
> {{annot.ocrText}}
{%- endif %}
{%- if annot.comment %}
> - **{{annot.comment|nl2br}}**
{%- endif %}
{% endfor %}
{%- endif %}
{%- endpersist -%}
{############## Green Annotations ##############}
{%- set annotGreen = [] -%}
{%- for a in annotAll -%}
{%- if a['colorCategory'] == "Green" -%}
{%- set annotGreen = (annotGreen.push(a), annotGreen) -%}
{%- endif -%}
{%- endfor -%}
{%- set annotGreenOld = [] -%}
{%- for a in annotOld -%}
{%- if a['colorCategory'] == "Green" -%}
{%- set annotGreenOld = (annotGreenOld.push(a), annotGreenOld) -%}
{%- endif -%}
{%- endfor -%}
{% persist "greennotes" %}
{%- if annotGreen.length > 0 -%}
{% if annotGreenOld.length <= 0 %}
### Very Important
{%- endif -%}
{% endif %}
{% if annotGreen.length > 0 %}
{%- for annot in annotGreen -%}
> [!quote|green]+ {{ calloutHeader(annot.type) }} ([Page {{ annot.pageLabel }}]({{ annot.desktopURI }}))
{%- if annot.annotatedText %}
> {{annot.annotatedText|nl2br}} {% if annot.hashTags %}{{annot.hashTags}}{% endif -%}
{%- endif %}
{%- if annot.imageRelativePath %}
> ![[{{annot.imageRelativePath}}]]
{%- endif %}
{%- if annot.ocrText %}
> {{annot.ocrText}}
{%- endif %}
{%- if annot.comment %}
> - **{{annot.comment|nl2br}}**
{%- endif %}
{% endfor %}
{%- endif %}
{%- endpersist -%}
{############### Grey Annotations ################}
{%- set annotGrey = [] -%}
{%- for a in annotAll -%}
{%- if a['colorCategory'] == "Gray" -%}
{%- set annotGrey = (annotGrey.push(a), annotGrey) -%}
{%- endif -%}
{%- endfor -%}
{%- set annotGreyOld = [] -%}
{%- for a in annotOld -%}
{%- if a['colorCategory'] == "Grey" -%}
{%- set annotGreyOld = (annotGreyOld.push(a), annotGreyOld) -%}
{%- endif -%}
{%- endfor -%}
{% persist "greynotes" %}
{%- if annotGrey.length > 0 -%}
{% if annotGreyOld.length <= 0 %}
### Methodology
{%- endif -%}
{% endif %}
{% if annotGrey.length > 0 %}
{%- for annot in annotGrey -%}
> [!quote|grey]+ {{ calloutHeader(annot.type) }} ([Page {{ annot.pageLabel }}]({{ annot.desktopURI }}))
{%- if annot.annotatedText %}
> {{annot.annotatedText|nl2br}} {% if annot.hashTags %}{{annot.hashTags}}{% endif -%}
{%- endif %}
{%- if annot.imageRelativePath %}
> ![[{{annot.imageRelativePath}}]]
{%- endif %}
{%- if annot.ocrText %}
> {{annot.ocrText}}
{%- endif %}
{%- if annot.comment %}
> - **{{annot.comment|nl2br}}**
{%- endif %}
{% endfor %}
{%- endif %}
{%- endpersist -%}
{############### Purple Annotations ################}
{%- set annotPurple = [] -%}
{%- for a in annotAll -%}
{%- if a['colorCategory'] == "Purple" -%}
{%- set annotPurple = (annotPurple.push(a), annotPurple) -%}
{%- endif -%}
{%- endfor -%}
{%- set annotPurpleOld = [] -%}
{%- for a in annotOld -%}
{%- if a['colorCategory'] == "Purple" -%}
{%- set annotPurpleOld = (annotPurpleOld.push(a), annotPurpleOld) -%}
{%- endif -%}
{%- endfor -%}
{%- persist "purplenotes" -%}
{%- if annotPurple.length > 0 -%}
{%- if annotPurpleOld.length <= 0 %}
### Confused / Have Further Questions
{%- endif -%}
{% endif %}
{% if annotPurple.length > 0 %}
{%- for annot in annotPurple -%}
> [!quote|purple]+ {{ calloutHeader(annot.type) }} ([Page {{ annot.pageLabel }}]({{ annot.desktopURI }}))
{%- if annot.annotatedText %}
> {{annot.annotatedText|nl2br}} {% if annot.hashTags %}{{annot.hashTags}}{% endif -%}
{%- endif %}
{%- if annot.imageRelativePath %}
> ![[{{annot.imageRelativePath}}]]
{%- endif %}
{%- if annot.ocrText %}
> {{annot.ocrText}}
{%- endif %}
{%- if annot.comment %}
> - **{{annot.comment|nl2br}}**
{%- endif %}
{% endfor %}
{%- endif %}
{%- endpersist -%}
{############### Blue Annotations ################}
{%- set annotBlue = [] -%}
{%- for a in annotAll -%}
{%- if a['colorCategory'] == "Blue" -%}
{%- set annotBlue = (annotBlue.push(a), annotBlue) -%}
{%- endif -%}
{%- endfor -%}
{%- set annotBlueOld = [] -%}
{%- for a in annotOld -%}
{%- if a['colorCategory'] == "Blue" -%}
{%- set annotBlueOld = (annotBlueOld.push(a), annotBlueOld) -%}
{%- endif -%}
{%- endfor -%}
{%- persist "bluenotes" -%}
{%- if annotBlue.length > 0 -%}
{% if annotBlueOld.length <= 0 %}
### Interesting References / Connected to the Larger Research Question
{%- endif -%}
{% endif %}
{% if annotBlue.length > 0 %}
{%- for annot in annotBlue -%}
> [!quote|blue]+ {{ calloutHeader(annot.type) }} ([Page {{ annot.pageLabel }}]({{ annot.desktopURI }}))
{%- if annot.annotatedText %}
> {{annot.annotatedText|nl2br}} {% if annot.hashTags %}{{annot.hashTags}}{% endif -%}
{%- endif %}
{%- if annot.imageRelativePath %}
> ![[{{annot.imageRelativePath}}]]
{%- endif %}
{%- if annot.ocrText %}
> {{annot.ocrText}}
{%- endif %}
{%- if annot.comment %}
> - **{{annot.comment|nl2br}}**
{%- endif %}
{% endfor %}
{%- endif %}
{%- endpersist -%}
{############### Orange Annotations ################}
{%- set annotOrange = [] -%}
{%- for a in annotAll -%}
{%- if a['colorCategory'] == "Orange" -%}
{%- set annotOrange = (annotOrange.push(a), annotOrange) -%}
{%- endif -%}
{%- endfor -%}
{%- set annotOrangeOld = [] -%}
{%- for a in annotOld -%}
{%- if a['colorCategory'] == "Orange" -%}
{%- set annotOrangeOld = (annotOrangeOld.push(a), annotOrangeOld) -%}
{%- endif -%}
{%- endfor -%}
{%- persist "orangenotes" -%}
{%- if annotOrange.length > 0 -%}
{% if annotOrangeOld.length <= 0 %}
### Definitions / Sources for Literature Review
{%- endif -%}
{% endif %}
{% if annotOrange.length > 0 %}
{%- for annot in annotOrange -%}
> [!quote|orange]+ {{ calloutHeader(annot.type) }} ([Page {{ annot.pageLabel }}]({{ annot.desktopURI }}))
{%- if annot.annotatedText %}
> {{annot.annotatedText|nl2br}} {% if annot.hashTags %}{{annot.hashTags}}{% endif -%}
{%- endif %}
{%- if annot.imageRelativePath %}
> ![[{{annot.imageRelativePath}}]]
{%- endif %}
{%- if annot.ocrText %}
> {{annot.ocrText}}
{%- endif %}
{%- if annot.comment %}
> - **{{annot.comment|nl2br}}**
{%- endif %}
{% endfor %}
{%- endif %}
{%- endpersist -%}
{############### Magenta Annotations ################}
{%- set annotPink = [] -%}
{%- for a in annotAll -%}
{%- if a['colorCategory'] == "Magenta" -%}
{%- set annotPink = (annotPink.push(a), annotPink) -%}
{%- endif -%}
{%- endfor -%}
{%- set annotPinkOld = [] -%}
{%- for a in annotOld -%}
{%- if a['colorCategory'] == "Magenta" -%}
{%- set annotPinkOld = (annotPinkOld.push(a), annotPinkOld) -%}
{%- endif -%}
{%- endfor -%}
{%- persist "pinknotes" -%}
{%- if annotPink.length > 0 -%}
{% if annotPinkOld.length <= 0 %}
### Miscellaneous
{%- endif -%}
{% endif %}
{% if annotPink.length > 0 %}
{%- for annot in annotPink -%}
> [!quote|pink]+ {{ calloutHeader(annot.type) }} ([Page {{ annot.pageLabel }}]({{ annot.desktopURI }}))
{%- if annot.annotatedText %}
> {{annot.annotatedText|nl2br}} {% if annot.hashTags %}{{annot.hashTags}}{% endif -%}
{%- endif %}
{%- if annot.imageRelativePath %}
> ![[{{annot.imageRelativePath}}]]
{%- endif %}
{%- if annot.ocrText %}
> {{annot.ocrText}}
{%- endif %}
{%- if annot.comment %}
> - **{{annot.comment|nl2br}}**
{%- endif %}
{% endfor %}
{%- endif %}
{%- endpersist -%}
{%- endif -%}