Zotero Integration – Import Templates?

Hi,

I’m sorry but I know very little about creating templates and I need some help.

When I add annotation to an item in Zotero I managed to include all I want from my notes including tags. However, once I import the annotations into Obsidian it has everything but the tags of each coment. I know it is a problem of my zotero template in obsidian. But as much I tried it is imposible to do it.
If you guys can help me with some easy customisation into my template I would be forever greatful.

Here is my template:


year: {{date | format (“YYYY”)}}
tags: research
authors: {{authors}}
tags: [literature-note, {% for t in tags %}{{t.tag}}{% if not loop.last %}, {% endif %}{% endfor %}]

Abstract: {{abstractNote}}

{{title}}

{{pdfZoteroLink}}

Notes

{% for annotation in annotations -%}{%- if annotation.annotatedText -%}{% if ‘Red’ in annotation.colorCategory %}

{{annotation.annotatedText | escape }}{% else %}

{{annotation.annotatedText | escape }} ({{annotation.page}})
{% if tags.length > 0 -%}{% for t in tags -%}#{% if t.tag == “secondary” %}source/secondary{% if not loop.last %}{% endif %}{% elif t.tag == “primary” %}source/primary{% if not loop.last %}{% endif %}{% elif “-project” in t.tag %}project/{{t.tag | lower | replace(" “, “-”) | replace(”-project", “”)}}{% else %}subject/{{t.tag | lower | replace(" “, “-”)}}{% endif %}{% if not loop.last %} {% endif %}{%- endfor %}{%- endif %}
{% if tags.length > 0 -%}{% for t in tags -%}#{% if t.tag == “secondary” %}source/secondary{% if not loop.last %}{% endif %}{% elif t.tag == “primary” %}source/primary{% if not loop.last %}{% endif %}{% elif “-project” in t.tag %}project/{{t.tag | lower | replace(” “, “-”) | replace(”-project", “”)}}{% else %}subject/{{t.tag | lower | replace(" ", “-”)}}{% endif %}{% if not loop.last %} {% endif %}{%- endfor %}{%- endif %}
{% if hashTags %}Keywords:: {{hashTags}}{% endif %}

{% if hashTags %}Tags: {{hashTags}}{% endif %}
{% endif %}{%- endif %} {% if annotation.imageRelativePath %} ![[{{annotation.imageRelativePath}}]]{% endif %}{% if annotation.comment %}

{{annotation.comment}}
{% endif %}{% endfor -%}

Thank you!

You are not accessing the tags and hashTags correctly.

Tags, as you have them here, are for the top-level tags associated with the item, not each annotation.

I see that you’ve adopted the tags snippet from @erazlogo (originally at the top of the note) and applied it to your annotations. I don’t see how the logic of reformatting primary and secondary tags is useful to apply to each annotation. These tags seem intended to characterize the whole source.

You certainly don’t need both tags and hashTags, especially since you are applying a hashtag to the tags too.

Anyway, for both tags and hashTags, you need to access them under the annotations key. When accessing the annotations key array using {% for annotation in annotations -%}, the “annotation” part is arbitrary (it could be for a in annotations for example), so you need to use this same variable in the later code.

tags are a bit more complicated to access, but applying what I wrote above, we get:

{% if annotation.tags %}{% for t in annotation.tags %}#{{t.tag}}{% if not loop.last %}, {% endif %}{% endfor %}{% endif -%}

For hashTags, this will do:

{% if annotation.hashTags %} {{annotation.hashTags}}{% endif %}

You were missing the “annotation” part. Take a look at the Data Explorer (ctrl / cmd + P and search “Data explorer”) to see how the data is structured and why your previous attempt didn’t work. Look under annotations.

To see an example with this implemented in the larger code context, check out my template here: Zotero Integration – Import Templates? - #105 by Feralflora

1 Like

@Feralflora
Hi Feralflora.
First let me give my thanks for your amazing work whith this template!!!
I’m a new user of Zotero integration after leaving Annotator.
I’m facing a problem when I higlight text - import it it’s making the categories as expected.
However when I higlight more text and do a new import, it creates the categories again
Thanks for your help

https://i.imgur.com/5sEMwq5.png

1 Like

Hey David, welcome to the forum! And thanks for the kind feedback :blush:

Yes, you have discovered a limitation of Zotero Integration, namely that new annotations are appended at the end, when updating your notes. This is a consequence of how persistence works, namely by surrounding your imported annotations with markdown comments like so:

%% begin annotations %%
%% end annotations %%

Everything between these fields will persist as is between updates. This is to protect comments, block-ids, highlighting and other stuff you might add later. Therefore, new annotations are appended at the end, including the heading they belong under.

This is rather unfortunate, but necessary. I should add that qwxlea’s template tries to solve this by having every annotations in its own persist field, rather than having one for all of them. You could give that a try, but note that this approach causes some issues of its own, as you can see here.

My suggestion would be to try to finish annotating before importing, although this is not always possible, especially with longer texts. Alternatively, you could get rid of persistence on the annotations, if you can live without, but this could lead to data loss. Lastly, you can forgo grouping, and use my sequential template. This way, you won’t have duplicate headings. However, this is probably not an attractive option.

By the way, you can upload and attach images here directly, no need to use imgur.

1 Like

Hey thanks for replying :grin:

I’ve looked at qwxlea’s template but find it less convenient than yours.
I’m gonna try your alternatives.
By the way, I’ve started to read Nunjucks documentation to make my own template inspired by yours and qwxlea’s.
Let’s see If I can produce something valuable :blush:
Have a nice day

2 Likes

There’re a few templates here

2 Likes

Hello Feralflora, Hello everybody,

i am just starting with Obsidian so i might ask quite obvious or stupid stuff (sorry in advance!). I already got some basic idea what i want to do with my Vault due to excellent feedback on another post i wrote. Thank you @Feralflora for your beautiful template (even though i havent figured out all parts of it :slight_smile:

Short introduction: i am a veterinarian and i am mostly dealing with animal welfare at transport and slaughter. in my free-time i am researching and wrote a few papers. The zotero-obsidian connection opened a whole new world for my workflow. The problem is that i have basically zero experiences in coding and markdown. I watched a whole bunch of videos and read a lot of articles in the last weeks and there is some improvement.

major next step:

  1. getting the zotero-obsidian connection to work. This post has helped immensly but i am not there yet.
  2. setting up a similar routine for other sources (Newspaper articles, books, videos)

what i have done so far:

  1. Decided that i want a flat folder structure in my vault with only a few folders: Literature notes, Fleeting Notes, Attachments, Templates, Zettelkasten
  2. Installed the Zotero addon: BetterBiblaTex
  3. Installed the Obsidian plugins: Zotero Integration, List callouts
  4. Tried to setup the process by following this post and other posts on the Obsidan Forum and videos by Bryan Jenks and others
  5. used the template supplied by Feralflora
  6. Imported an expample paper from zotero and managed to automate saving the pictures in an attachment folder and the highlights in a note by using Feralfloras template

right now these questions remain:

  1. why does my graph view look like this:
  2. how should i proceed for other sources than journal articles? (use other templates? if yes, where can i find them)

Thank you in advance for your help. If you offer me help with my vault i can answer your questions regarding the health of your cat/dog/any animal :slight_smile: :joy:

one more question:

what is the “key takeaways” and “processing” part of the template. it is empty. so where do i enter the data?

Hey @PR2ndbrain, and welcome to the forum!

You write this, but from your subsequent points under “what I have done so far”, it sounds like you’ve got a solid, functional system already. The questions you have seem to be fairly minor issues:

That appears to be the local graph (or an equivalent zoomed-in view of the global graph) of your Zotero Integration template. You can tell by the grey color that the code variables are not actual notes, but links that could be realized.

This is merely a consequence of the fact that the template contains links that will be made when you import an item from Zotero as a literature note. This includes links to: images, each author of an item, and a link to the collection names the item belongs in.

To eliminate these links from your graph, add this under Filters in the graph options (upper right corner of the Graph):
-path:"Your/Template/Path", with your actual template path.

In addition, if you are not interested in creating author notes and collection notes, then you can remove the square brackets that surround these in the info callout.

My template is sort of geared towards Journal articles, I must admit. For example, I don’t distinguish between creator types. There are some examples in this thread of more dynamic processing of creators and such, as well as importing the item type and storing that in the frontmatter. You could add those parts to the template to accommodate other sources (I will do this in a future updated version).

Zotero can handle many types of sources, so this should be a viable option. It also added annotation support for webpages and Epubs in the latest Zotero 7 betas.

I use Readwise to store and import newspaper articles, tweets and such, so I have a template for that which is sort of similar to this one, in that it also formats the annotations as a list. However, Readwise is not free. There is also Omnivore, which is free and open source, but I can’t comment on that since I haven’t tried it.

You are meant to fill these in yourself in Obsidian after importing (given that you want such a workflow). The code fields there are cursor placeholders that you can jump to, in order to quickly add the information. You need the templater plugin for this, which is very widely used. I have a hotkey set up so I just need to press ctrl + J to jump to the next cursor location.

Thank you @Feralflora for your answer. For now i feel ready to get down to actual writing notes :blush:. Thank you for your time and effort - with the fantastic template and the answer to my questions. Having a a community like this is obviously what makes Obsidian great!

1 Like

Hi - super noob question but I am not a coder - just a tired dad trying to make his front matter work (for “list” type property field)

I am trying to parse each author as a [[wikilink] in the front matter but I don’t know how to format the line breaks I guess its not “\n” or I am putting it in the wrong place

currently:

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

produces this output:

authors: - “[[Samir Agrawal]]”\n - “[[Padman Vamadevan]]”\n - “[[Ndaba Mazibuko]]”\n - “[[Robin Bannister]]”\n - “[[Raphael Swery]]”\n - “[[Shanna Wilson]]”\n - “[[Sarah Edwards]]”

… I need help making it a list recognised by the properties syntax

any help is appreciated

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