Is it possible to add conditional statements in Zotero import templates (and how can it be done )?

Hi everyone,

I am a huge obsidian noob ( discovered it less than a week ago) and I’m trying to setup my personal workflow with appropriate templates. The potential seems overwhelming, but I’m a little bit lost. Very sorry then if my problem is an obvious one !

Things I have tried

I’m linking Obsidian with Zotero using bibnotes and I retrieve all the zotero’s tags and convert them as tags in obsidian as well.
In Zotero, I use a specific tag “#Read” when I’ve read an article, but I don’t use an opposite one (which would be “#toRead”)

What I’m trying to do

In my bibliographic Zotero template, I want to add a tag, for instance “#toRead”, if there is already no tag #Read" in the tag list.
Is it possible and how can I do that ?

Any pointers or tips would be greatly appreciated !!! :wink:

1 Like

Which Community Plugin for Obsidian are you using for the Zotero imports? And what plugin do you use for making templates? Your options depend on those!

Thanks for your answer ! :+1:
I’m using the BibNotes Formatter plugin (GitHub - stefanopagliari/bibnotes) on Obsidian’s side, and the BetterBibTex plugin on Zotero’s side.
Do you need more information ?

1 Like

Thank you, and thank you for including the links to save me some time! First thing to know, which it seems like you may already know the answer to, is which field your Zotero #Read tag shows up in when you make a bibliographic note. (If you don’t know the answer, you could stick all the potentially relevant sounding fields from the custom fields list in a template, import something from Zotero that you know has #Read, and see which template field the tag shows up in.

The other thing to find out is how to do a conditional check (aka if statement) inside a BibNotes Formatter template, so that you can check whether #Read already exists, and if not, add #ToRead. I cannot see how to do a conditional from a quick look at either the documentation or the source code of the plugin, but @stpag has a forum account so maybe you’ll be able to get a direct answer!

An alternative option, since this particular check you want to make is about tags, would be to see if any of the existing community plugins for adding and modifying tags can do the conditional check.

That’s all I’ve got: good luck!

Although it may not actually work the way I imagine, I had an idea for a way to use regex search and replace to accomplish something that may do the job. However, it depends on how you add your tags, so I will wait until I find out before I share the expressions. The question is whether you always add the #read tag as a standard tag. Or are there cases where you use frontmatter. I would also want to know how you generally setup your notes so I can try to avoid any negative consequences.

My thought would be to use a two step process to accomplish the goal. First, you would use a regex search and replace to add a #toRead tag at the end of every note. Then, you could use another regex search and replace with capture groups to search for all notes that have some content (capture group 1), a #read tag, some more content (capture group 2), then finally a #toRead tag. The expression would only find these notes that have the #read tag and the replace expression would return the optional initial content, the #read tag, and finally the optional following content leaving out the #toRead tag. So essentially the process first adds the #toRead tag to all in step one then removes the #toRead tag from all notes that have both the #read and #toRead tag.

This is kind of a clunky way to do it, but unless I am missing something, I believe it should work. So, when you get a chance, @TTLyon let me know about the general format of your notes and I could try to write and test that the search and replace regular expressions that I am envisioning work. Good luck and thanks for asking this intriguing question. Trying to come up with a solution helped me solve a problem I didn’t know I had.

1 Like