Zotero Integration: Keep the writing made on Obsidian after importing new annotations/updating the note?

Hello,

Sorry for the messy title, English is not my first language.

I just set up Zotero Integration. It seems to work great as long as one does not need to make new annotations in Zotero. Here is my wished workflow:

  1. In Zotero: make annotations with short comments
  2. In Obsidian: import the annotations
  3. In Obsidian: do a lot of writing about the annotations/short comments
  4. In Zotero: add new annotations to the paper
  5. In Obsidian: import only the new annotations / update the paper without losing the writing done on step 3.

Step 5 is where I am struggling. Is there a way to do that?

I am using a template, so maybe with something to add to the note only new annotations created after the “last modified” time in Obsidian? Or maybe something even easier.

Thank you in advance.

Hi Sulth,

Yes, this is possible. It’s covered in Zotero Integration’s templating docs.

What you need is this part of the code examples:

{% persist "annotations" %}
{% set newAnnotations = annotations | filterby("date", "dateafter", lastImportDate) %}
{% if newAnnotations.length > 0 %}

### Imported: {{importDate | format("YYYY-MM-DD h:mm a")}}

{% for a in newAnnotations %}

{# YOUR ANNOTATION FORMATTING #}

{% endfor %}

{% endif %}
{% endpersist %}

Note that the new annotations will be appended below your old ones. This is because persistence of the old annotations also excludes the possibility of updating as-is. Therefore, changes / updates can only be appended.

Hi Feralflora,

Thank you for your answer. I am so sorry to use your time, but I really struggle to implement this into my template. I don’t know where it should go or what to delete/replace. Would you mind orienting me?

Here is what I’m working with:

{% for annotation in annotations -%}
    {%- if annotation.annotatedText -%} 
		- <mark class="hltr-{{annotation.colorCategory | lower}}">"{{annotation.annotatedText | escape}}”</mark> [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 -%}

Thank you. Have a good day.

1 Like

I assume your annotation formatting is functional? I didn’t look into that, just surrounded it by the persist correctly. Give this a try:

{% persist "annotations" %}
{% set newAnnotations = annotations | filterby("date", "dateafter", lastImportDate) %}
{% if newAnnotations.length > 0 %}

### Imported: {{importDate | format("YYYY-MM-DD HH:mm")}}

{% for annotation in newAnnotations %}

    {%- if annotation.annotatedText -%} 
		- <mark class="hltr-{{annotation.colorCategory | lower}}">"{{annotation.annotatedText | escape}}”</mark> [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 %}

{% endif %}
{% endpersist %}

You probably need to play around with the whitespace control while previewing the template in the Data explorer.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.