Zotero Integration – Import Templates?

Thank you very much for your resource material made publicly available. It is extremely valuable.

If anyone is interested, I have made some changes to the template to cater to the new Properties features and also annotation tags.
See multiple variations with some custom options here:

NB: For the template there to work (with the project tag conversion and all), you need to have the author’s javascript files filed away.

Thanks everybody for your great templates! I’m currently building my own and was wondering if it’s possible to export each child-note in Zotero into separate Markdown files, ideally a linked to from a metadata file?

For longer books, I tend to write quite extensive notes, separated by chapter and filled with copy-pasted annotations, and the Zotero note can get really long in that case. Ideally, I could loop through all notes and create a new file for each.

My current code looks like this, but lacks the capability to create separate notes:

{% for note in notes -%}
{%- set noteID = ["id-", note.key] | join | lower -%} 
{% persist noteID %}
{% if note.dateModified > lastExportDate %}

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

Thanks!

In addition, if any of you know how to modify the above code in order to persist notes that have not been modified but override notes that have been modified?

I want to be able to add block references, additional notes, once a Zotero note is “finished.” With the code above, the modified note is appended, which is quite annoying to clean up

I think you may be conflating some things here, because nothing in @erazlogo’s Zotero Integration template itself relies on Templater or any javascript. The tag conversion is handled by Zotero Integration using nunjucks without the involvement of Templater.

Templater and user scripts aren’t used until after the import for processing the imported note and extracting content to new notes.

1 Like

Indeed. Noted. Corrected.

Conflation happens, when you try to do a Templater script that is above your head. :slight_smile:

1 Like

I would appreciate assistance with two queries re: modification to a zotero integration template:

  1. for extracting images in zotero markdown notes: ie additional lines for this chunk
    {%- if markdownNotes %}
    {{markdownNotes}}
    {%- endif -%}

  2. extracting tags that are added in the zotero markdown notes ie tags written within zotero notes
    Thanks

Hi, I’m new to this thread, and I just encountered the same problem of having grey boxes.

After many trials and errors, I figured out how to solve this. You need to add this CSS file https://github.com/lguenth/obsidian-templates/blob/main/css/litnote-colors.css to the snippet directory in order for it to work (shout out to @apfelstrudelig). So first, in Obsidians, you need to go to Settings → Appearance → scroll down to CSS snippets. Then there is a folder icon to the right (next to the refresh icon), click that. It will lead you to the .obsidian/snippets folder. Then, create a plain text file called callouts.css. Paste the code in the link above to that file and save it. Then go back to Obsidian, you should see a new line called “Apply CSS snippets at …”. Enable that and load the template again, you should be able to see the colored boxes now.[quote=“JGA, post:104, topic:36310, full:true”]
Thanks for sharing this, really useful :slight_smile: One thing that happens to me is that if I use your template, I get all the headers and the heading symbols as in your picture, but everything is in a grey colour, meaning that Major Statements are in grey and Ordinary notes are in grey too, as opposed to having green and yellow callout boxes. Any idea on why this is the case, as I am not changing your template?
[/quote]

4 Likes

I think this is the CSS snippet that is used.

Thanks, @Feralflora for the incredible template!

Just in case anyone would like to display the comments after the texts as I do, you can so so by modifying @Feralflora 's template as

(replacing the entire ‘{% persist “annotations” %}’ block):

{% persist "annotations" %}
{% set annotations = annotations | filterby("date", "dateafter", lastImportDate) -%}
{% if annotations.length > 0 %}
*Imported on {{importDate | format("YYYY-MM-DD HH:mm")}}*

{% for color, annotations in annotations | groupby("color") -%}

### {{heading(color)}} %% fold %%
{% for annotation in annotations -%}
{%- if annotation.imageRelativePath %}
> [!cite]+ Image [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}})
> ![[{{annotation.imageRelativePath}}]]{% if annotation.hashTags %}
> {{annotation.hashTags}}{% endif %}{%- if (annotation.comment or []).indexOf("todo ") !== -1 %}
> - [ ] **{{annotation.comment | replace("todo ", "")}}**{% else %}
> **{{annotation.comment}}**{%- endif -%}

{% elif (annotation.comment or []).indexOf("todo ") !== -1 %}
- [ ] **{{annotation.comment | replace("todo ", "")}}**: {% if not annotation.annotatedText %} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}){% else %}
	- {{calloutCharacter(annotation.color)}} {{annotation.annotatedText | nl2br}} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}) {% if annotation.hashTags %}{{annotation.hashTags}}{% endif -%}{% endif -%}

{% elif annotation.comment %}
- {{calloutCharacter(annotation.color)}} {{annotation.annotatedText | nl2br}} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}) {% if annotation.hashTags %}{{annotation.hashTags}}{% endif %}
	- **{{annotation.comment}}** {% if not annotation.annotatedText %} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}){% else %}{% endif %}
{%- elif annotation.annotatedText %}
- {{calloutCharacter(annotation.color)}} {{annotation.annotatedText | nl2br}} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}) {% if annotation.hashTags %}{{annotation.hashTags}}{% endif %}
{%- endif -%}{%- endfor %}

{% endfor -%}
{% endif %}
{% endpersist %}
1 Like

Hey @untidytexts, thanks for the feedback and also taking time to switch this around for people! I did the same thing earlier in the thread for my initial version of the template, but hadn’t for this one.

I haven’t tested your adjustment, but I noticed that you haven’t switched the order of comments starting with “todo” (the ones that get formatted as tasks). Is that by choice?

1 Like

Ah, I missed out on that one! So this updated snippet should work, just tested it with an example -

{% persist "annotations" %}
{% set annotations = annotations | filterby("date", "dateafter", lastImportDate) -%}
{% if annotations.length > 0 %}
*Imported on {{importDate | format("YYYY-MM-DD HH:mm")}}*

{% for color, annotations in annotations | groupby("color") -%}

### {{heading(color)}} %% fold %%
{% for annotation in annotations -%}
{%- if annotation.imageRelativePath %}
> [!cite]+ Image [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}})
> ![[{{annotation.imageRelativePath}}]]{% if annotation.hashTags %}
> {{annotation.hashTags}}{% endif %}{%- if (annotation.comment or []).indexOf("todo ") !== -1 %}
> - [ ] **{{annotation.comment | replace("todo ", "")}}**{% else %}
> **{{annotation.comment}}**{%- endif -%}

{% elif (annotation.comment or []).indexOf("todo ") !== -1 %}
{% if not annotation.annotatedText %} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}){% else %}
- {{calloutCharacter(annotation.color)}} {{annotation.annotatedText | nl2br}} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}) {% if annotation.hashTags %}{{annotation.hashTags}}{% endif %}
	-  [ ] **{{annotation.comment | replace("todo ", "")}}**{% endif %}
{% elif annotation.comment %}
- {{calloutCharacter(annotation.color)}} {{annotation.annotatedText | nl2br}} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}) {% if annotation.hashTags %}{{annotation.hashTags}}{% endif %}
	- **{{annotation.comment}}** {% if not annotation.annotatedText %} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}){% else %}{% endif %}
{%- elif annotation.annotatedText %}
- {{calloutCharacter(annotation.color)}} {{annotation.annotatedText | nl2br}} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}) {% if annotation.hashTags %}{{annotation.hashTags}}{% endif %}
{%- endif -%}{%- endfor %}

{% endfor -%}
{% endif %}
{% endpersist %}
1 Like

When using the above templates, where in the properties section authors are pulled in from Zotero using {{authors}}, my graph view gets clogged with inactive nodes which represent all the authors from said article. Is there any way to circumvent this as to not clog up the graph view?

image

Yes, there are several ways to do that:

  • Remove the square brackets from the author names in the template
  • Enable existing files only in the graph settings.

Hi Feralflora,

Thank you SO much for your very helpful template! I believe it will be very useful for my studies. Two questions for you:

  1. The beginning bits of information from my Zotero pdf don’t seem to populate (e.g., abstract). The other callouts work (e.g., important, questions, etc.). I wasn’t sure why this was happening.

  2. Sometimes, the template doesn’t populate at all for my Zotero pdfs. Even though I have highlighted and made notes in Zotero.

Any advice would be awesome. Thank you!!

Hi Kristi, I’m glad you find my template useful.

Let’s address those issues you’ve had:

Are you sure the item you’ve imported has an abstract in its abstract field in Zotero? For the other ones, have you made sure to actually expand the callout? They are collapsed by default, and you need to click to open them.

The part about other callouts is a bit unclear, because there are no callouts like “Important” and “Questions” in my template, those are just headings for each annotation category. Do note that you can and should change these categories to fit your needs.

Key takeaways and processing is stuff that you have to write yourself, in case you thought that it was an issue that these are empty. The code there are cursor placeholders you can jump to with a hotkey, if you set such a hotkey up for the Templater plugin (required for this to work).

Do you mean you have several PDFs under an item? I’m not sure I’ve added support for importing annotations from several PDFs. I can check when I’m at home with my desktop PC.

If there issue is the same as mine, it’s that I get no PDF annotations. I can get them just fine if I make the annotations a separate note (they’ll come under the note section). However, I’m not getting PDF annotations from the PDF itself.

I have reinstalled, rolled back, etc.

edit: I just tried with a new PDF and it brought everything in fine :man_shrugging:t2:

:loudspeaker: PSA to all nunjucks templaters, struggling or otherwise:

Zotero Integration’s Data Explorer (found in the command palette) now features a context menu with template helpers where you can right-click and copy the template code that captures a particular field:

3 Likes

Hi @galachus! Re: the above :point_up:
This is maybe not as relevant to you now, since I assume you’ve already set List Callouts up.
But anyway, I thought it would be useful for you and others to know that the List Callouts plugin just got a much-needed search box for icons:

:tada:

2 Likes

I know it has been a while since you posted these, but wanted to say thanks so much for being so generous with your work and time/responses: I’m pretty new to Obsidian, but your template and ideas have given me a very solid foundation for my workflow (as an academic reading lots of papers!).

cheers.

4 Likes

Thanks for the feedback, it means a lot to me! :heart:

I haven’t posted about it yet, but I have an updated version of my template with many improvements over on GitHub that you might be interested in:

I will go more into details about the changes at some point. The basics are still the same, but there are many QOL improvements, new edge cases considered, and other little innovations.

2 Likes