Zotero Integration – Import Templates?

This is the template that I use, which is compatible with Properties:

{%- for type, creators in creators | groupby("creatorType") %} 
{% if creators.length > 1%}{{type}}s:{%- for creator in creators %}{% if creator.name %}
- {{creator.name}}{% else%}
- {{creator.firstName}} {{creator.lastName}} {% endif %}{%- endfor %} {% else -%}
{{type}}:{%- for creator in creators %}{% if creator.name %} "{{creator.name}}"{% else%} "{{creator.firstName}} {{creator.lastName}}"{% endif -%}{%- endfor -%}{% endif -%}{% endfor %}

However, I group by creator type and make the creator type plural or singular, depending on the number of creators in each group.

To get your own template to work as intended, here’s the changes I made:

Obsidian_ZuUVuO30RS

And here’s the resulting snippet

authors: {%- for creator in creators %} {%- if creator.name == null %} 
- “[[{{creator.firstName}} {{creator.lastName}}]]”{%- endif -%} {%- if creator.name %} 
- “[[{{creator.name}}]]” {%- endif -%}{%- endfor %}

Note that I used Data Explorer to debug this. It’s very useful. It’s found in the command palette (just search for Data explorer).

2 Likes

wow thanks so much for such accurate support and great tips. I did use data explorer - I had forgotten about this tool! thanks again! I am going to explore your template in more detail this weekend

1 Like

You’re welcome, glad I could help! Good luck with the exploring :wink:

I am doing a deep dive into this. I would be grateful for people’s thoughts on the following as I refine my workflow too…

  • Are there many people using Zotero for ‘lecture slides’ as well as academic articles? a Zotero template variant for this style could easily be made to draw from the workflows in this thread. I think this is a core issue for many academics and I am very divided on if I should store my PDF’s for lecture slides directly in Obsidian, or use Zotero for this (and its ability to import highlights using the above workflows). I also ask because there doesn’t seem to be a default ‘item type’ in Zotero for ‘lecture’
  • Can Zotero make a ‘saved search’ for PDF files that contain notes or highlights? (I have tried to find this out) rather than manually tagging them
  1. There is a “presentation” item type in Zotero. Doesn’t that cover Lectures too? So that is quite a viable way to do it, but there are also good tools in Obsidian for working with slides, specifically the Slide note plugin that allows you to embed specific pages of PDFs, scale them etc. Either way, you do have options, and I’m not sure what’s best. You probably have to experiment a bit.

  2. Yes, the setup is like this:

But it’s also a bit cluttered, because I have a lot of items with autogenerated notes, which I am not so interested in.

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.