Anki Forums

Conditional Card Creation with JavaScript

Hi there,

I am trying to figure out a way of creating cards only if a script provides a certain value. Any thoughts on how to implement that?

Any ideas are highly appreciated. :slight_smile:

Card creation is done on the backend. A card is created if the evaluation of field replacements on the front side yields any text. Anything else, including script tags, is treated as literal text and not evaluated in any way.
Maybe if you explain your intentions, someone can come up with another way to achieve your goal.

1 Like

My goal is to recreate the function of Cloze Overlapper with Closet for Anki to be able to use it in different card types. To do this, I want to read one specific line from a field at a time and write it as a Cloze. (Regarding this, Iโ€™m still missing a solution aswell). Since Closet makes the clozes dependent on the card number of the note, you have to hard-code that in advance (as far as I can tell). This is not a problem, but then all cards are always created (e.g. always 10 cards), even if the last cards have no content. To prevent this, I am looking for a way to create the affected cards only if actually row x exists. Hope this makes sense.

Is there a field, upon which you can base your card? If that field is empty, you do not display anything else, and so the card is empty/clear and Anki will not display it?

{{# my_control_field }}
{{ Front }}
{{/ my_control_field }}

If that does not suit, have a look at this post.

I think I had the same question on reddit a while ago:

Iโ€™m afraid it doesnโ€™t work.

Maybe this deck could provide a workaround:
https://ankiweb.net/shared/info/1637056056