Sorry to burden the community with a code bug for a template for the Zotero Integration Plugin.
I have no coding experience, but I’ve been trying to combine two different templates I’ve found online.
The base code works for colour-coding highlights and adding new timestamps when further highlights are added.
I’m trying to add a feature from Danny Hatchers template where it automatically leaves a link at the end of the highlight to take you directly to the page in the original document in Zotero.
I’m missing something to trigger the link code correctly as it runs, but it doesn’t correctly reference the page number and, hence, doesn’t work taking you to the original highlight.
If this is easy to spot for someone else, I’d be most appreciative - I’m a couple of hours in and getting nowhere.
Cheers, and see the code below:
###### Highlights
{%- macro calloutHeader(type, color) -%}
{%- if type == "highlight" -%}
<mark style="background-color: {{color}}">Quote</mark>
{%- endif -%}
{%- if type == "text" -%}
Note
{%- endif -%}
{%- endmacro -%}
{% persist "annotations" %}
{% set newAnnotations = annotations | filterby("date","dateafter", lastImportDate) %}
{% if newAnnotations.length > 0 %}
###### Imported: {{importDate | format("YYYY-MM-DD")}}
{% for a in newAnnotations %}
{{calloutHeader(a.type, a.color)}}
{{a.annotatedText}}[Page {{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}&annotation={{annotation.id}})
{% endfor %}
{% endif %}
{% endpersist %}
Thank you both for the help and reply - I really appreciate it.
@Feralflora, I came across your GitHub template, which looks fantastic, but as you can see from my non-existing coding, I was too intimidated to try it after already struggling with this basic setup.
However, editing the page without having it overwritten when you re-import a highlight is a great feature. I couldn’t figure it out (even with one of the basic templates (half the code) claiming edits were safe), so I’ll do a two-step process for now until I hopefully improve my setup.
Anyway, I took your suggestions, and they worked to generate the correct page number and automatically opened the PDF in Zotero (thanks).
However, Zotero didn’t move the screen to the specific section of the paper with the highlight. Any idea where I went wrong?
See attempt 1
{% for a in newAnnotations %}
{{calloutHeader(a.type, a.color)}}
{{a.annotatedText}}[Page {{a.pageLabel}}](zotero://open-pdf/library/items/{{a.attachment.itemKey}}?pageLabel={{a.pageLabel}}&a={{annotation.id}})
{% endfor %}
{% endif %}
{% endpersist %}
Attempt two:
{% for a in newAnnotations %}
{{calloutHeader(a.type, a.color)}}
{{a.annotatedText}}[Page {{a.pageLabel}}](zotero://open-pdf/library/items/{{a.attachment.itemKey}}?pageLabel={{a.pageLabel}}&a={{a.id}})
{% endfor %}
{% endif %}
{% endpersist %}
Both code lines returned a similar result.
Cheers!
You’re welcome! Please mark this issue as resolved, and ideally, you should post your other question as a separate thread to get more eyes on the matter and keep the forum organized. But since it’s a simple matter, I’ll answer here:
Instead of constructing the URI manually as you’re doing, just use the ready-made one available as {{a.desktopURI}}.
I construct the link like so (inside the for-loop over the annotation array):
Then you would use citationLink like so: {{annotation.annotatedText}} {{citationLink}}
Note that you still need to use a where I used annotation above. Or you could drop the usage of a as a variable name, and switch everything to annotation, as that is more informative / intuitive.