Zotero Integration – Import Templates?

awesome, thanks - will check it out! :smiley:

1 Like

Hi @Feralflora,

I’ve been using your (new) template, and in my beginners - and complete coding/scripting neophyte - mind, had a couple of queries.

First - when importing from Zotero, I’ve noted that any tags written in zotero that have a space or comma delimiter get imported as two separate tags (e.g. ‘cardiovascular disease’ becomes ‘cardiovascular’ and ‘disease’, or ‘contraception, adolescent’ becomes ‘contraception’ and 'adolescent). I’ve figured out that I need to script something that says 'hey, take that ‘space’ or ‘,’ and deal with it, but I can’t quite figure out precisely where my script should go, and I can’t quite get it right.

Also - and this is more just to confirm something for myself - running your script as it is in github gets me a section that looks like this in my note:

I assume that this is because this section of your template is dependent on other templates/snippets in your vault? (basically if i remove that bit it won’t break anything else? :smiley: )

Once again, thanks for your template and replies above - definitely helping me muddle my way through learning a bit more about all this.

Hi @DisorganisedAcademic! Glad to see people trying the latest template version.

Is this true for all tags in the literature note, or in a specific place? Like in the properties, metadata callout or by the annotations? It should be easy to fix, when I know where you have the issue. I hadn’t really considered this, because I don’t use tags with spaces.

Yes, this is referring to the following Templater template that triggers an import when you push a button in the note:

<%* app.plugins.getPlugin('obsidian-zotero-desktop-connector').runImport('Import name',tp.file.title); %>

If you have the Buttons plugin installed, the code you asked about will render as a button in the template. You can safely delete the button code :slight_smile:

However, if you would like to try it out, note that “Import name” should be replaced with the actual name of the import (configured in Zotero Integration’s settings) that you want to run.

You also need to set a Template hotkey for this template in Templater’s settings. This makes it available in the command palette, which is what the button is expecting.

Lastly, the path in the button should reflect the actual path to the template in your vault.

I’ve written a guide that covers this template as part of a reading workflow I created that automatically imports Zotero items and metadata into a Kanban board in Obsidian based on tags in Zotero:

(I should probably make a forum post about this :point_up:)

1 Like

Should have mentioned that!

This is an illustration of what I mean.

I did try to write some code to fix it, but I just KNOW I’m doing something very simple and very simply incorrect :smiley:

I’ve written a guide that covers this template as part of a reading workflow I created that automatically imports Zotero items and metadata into a Kanban board in Obsidian based on tags in Zotero:

Excellent! Off to read it with my morning coffee (organising my obsidian absolutely counts as ‘work’ on a friday morning). Thanks, yet again.

1 Like

No problem, I’m glad my contributions help!

I’m taking a shot at this right now, so you could try it out if you are still up in your timezone in a little bit.

Oh, for sure :wink: :coffee:

1 Like

Okay, so the Obsidian behavior here is a bit strange. In the source yaml code, the tags are on separate lines as expected:

 - 📓
 - another tag
 - test tag
 - to-sort
 - unread

But when rendered as properties, the tags are considered separate, as you reported:


Since tags with spaces are not supported, I would expect that Properties would throw an error in this case, but apparently not, it just splits it when rendered.

Anyway, I’ve pushed at fix to GitHub that solves this by replacing spaces in tags with a dash (-) like so:

tags:{% for t in tags %}
- {{t.tag | replace(" ", "-")}}{% endfor %}

Aha! Excellent, thank you so much. I am also pleased to note that I wasn’t too far off on my own attempt :thinking:

Thanks again :smiley:

You’re welcome!
In the future, you can reference the nunjucks templating docs here: Nunjucks
It’s a great resource.

1 Like

Cheers - not sure if this is the time to mention that I HAD been referencing the nunjucks docs, just apparently not closely enough :laughing: (and it is an excellent resource - entirely operator error!)

1 Like

Hello! Is neophyte template maker here. Is it possible to mix sequential and color groupings in a template?

My situation is this. I highlight to mark things in terms of importance. Yellow is least important, then blue, and then red is most important. For these, I appreciate having them in sequential order, as they appear in the pdf.

The odd one out is the green highlighter. This marks sources I would like to follow up on. Ideally, I could gather all these green highlights under one heading, and then I can transclude that heading to a separate note for when I go to my university’s library.

Has anyone else done this kind of mixed method note? Thanks for the help!

Hi everyone,
I have a potentially stupid question:
I have an import template that used to simply import my written notes from zotero into a given section of the created literature note. however, this has stoped functioning properly and only transfers some parts of what I have written. Any ideas why?

This is the relevant (I guess) part of the template:
"# Notes
{% persist “notes” %}{% if isFirstImport %}

{{markdownNotes}} {% endif %}
{% endpersist %}"



The problem is likely that isFirstImport means that {{markdownNotes}} are only imported the first time you import the item, and then never again as you import.

If you remove this condition, the Zotero notes are imported each time you update. With the persist in place, new changes will be appended. Without it, the old notes are overwritten by the new ones.

Hi Feralflora,
Thanks for your quick reply. I tried your recommendation but it did not really change anything in terms of the results I get. I played around with the data explorer and have - if I understand this correctly - the impression that the problem might not lie with the import. Below, you see that only a very short part of my zotero-note (which continues considerably beyond the first heading) gets recognised by the data-explorer. any further ideas?


Hey @mgmeyers, thanks for the template, i tried it out but every annotation, no matter the colour in zotero, show under the header „interesting but not relevant“. It seems that the colours are in a way grouped correctly: When i have 2 things marked green in zotero, it shows those 2 things under the same heading. But again, all headings have the same name “interesting but not relevant”. any idea whats going on?

The css snippet does not seem to change the colour of the callouts, so i assume, theres something wrong with the colours, so that the template doesnt recognize the different colours in zotero correctly?

It’s because the colorValueToName macro doesn’t use Zotero color codes.

Since the Zotero colors don’t match any of the colors in the macro, they fall under the fallback default condition, which “Interesting but not relevant”.

I have a table with all the Zotero colors and color codes listed in this comment:

If you replace the color codes in the colorValueToName macro with these codes, then it should give you different headings.

The CSS snippet is also targeting the “wrong” color codes for you. So you need to change those to the Zotero hex codes.

1 Like

The code in the screenshot decides the heading to use based on the color. You are supposed to put different color #hex codes, so that annotations of different colors get grouped under different headings. As is, you only have the code for yellow highlights in there, so only yellow gets categorized. The rest fall under “default”. That’s why the headings are all the same.

Unless your needs match those of mgmeyers exactly, I also recommend that you change these headings / categories to something that is meaningful / useful to you.

As for the callout colors, it seems that you haven’t matched the hex codes correctly with the right rgb colors in the CSS snippet.

Do you mind explaining how to get the button working? I am looking to update annotations automatically or with a click of the button. Basically if I make a change in my Zotero annotations, I want to have it easily synchronise with my Obsidian.

I have this code

name Update literature note
type command
action Templater: Insert Templates/runImport.md
class update-lit-note

Then in a folder Templates/runImport with
<%* app.plugins.getPlugin('obsidian-zotero-desktop-connector').runImport('Create Literature Reading',tp.file.title); %>

I have the Templater and Button plugins both installed and on.

Can you think of any other reason why this might not be working when I click the button?

A prerequisite for this to work is that you add the template to the command palette. Go to Templater settings → Template hotkeys → Configure runImport as a hotkey. Now, it can be triggered directly from the command palette, and the button should work.

Hi, @SmartLittleOtter, just making sure I remembered to reply to your message, so you get notified.

1 Like

I think this link is broken @Zocahontas ?