Prevent card generation based on field input?

I make my cards with lots of fields, in a database like-way (for example the header will be the disease name, than i’ll have fields for cause, mechanism, symptoms, diagnosis, prognosis, therapy, and many others).

As often i find myself needing more “space” to ask those topics about disease (for example, if there are lots of categories and subcategories as causes of a disease), i usually create another note - usually a tree diagram note - just for that topic called “disease (causes)” and i fill the field in the original card with something like "check card “disease (causes)” " in order to

  1. know where to find what i’m searching at a glance if i search for it after a lot of time
  2. avoid filling again the field because i forget that there was already another more complex note.

The main problem with this strategy is that i have to manually suspend each card that the conditional generation create about those topics even so my note browser is often filled with lots of suspended cards; also i shared those decks a few time and they were almost unusable because the user had to manually suspend each card, continually breaking his learning.

The question is:

  • is there any way to avoid card generation if a specific content fills the field? In a similar fashion to /* */ for CSS?
  • If there isn’t, would it be possibile to add a feature like this?
  • If it isn’t possible, is there a better strategy that i could apply to solve this issue?

Thank you for your time! :slight_smile:

So you want to only generate cards if the field doesn’t contain a certain word like “check”? I don’t think this is possible, but Anki does have Selective Card Generation which depends on whether a certain field is empty. So you could add another field which you leave empty if you want a card to be generated or fill with arbitrary content if you don’t want that (or vice versa depending on your card layout).
If this doesn’t solve your problem, please try to explain your system again because I might have gotten it wrong.

1 Like

I know about the conditional replacement but since i have 50-100 fields for each note type it really isn’t feasible to make another 50-100 fields just to avoid generation. It would be an headache. What i would like to have is a way to avoid card generation based on the content of a field. For example “don’t create the card if field contain the * symbol” or like it is for CSS ignore everything that is contained between /* and */ so that even if the field is non-empty anki sees it as empty and doesn’t generate the card

Emtpy or not seems to be the only possible condition for card generation.
But if you have a unique string for fields that are only to be used for reference, you can at least search for that string and suspend the cards in question on bulk, can’t you? You can then also give them a tag, so users of your deck will just have to suspend all the cards with that tag.

Another option would be to store all the reference information in a single field and use JavaScript to generate the appropriate HTML from it. Thus, you would make use of Anki’s conditional card generation while still accomplishing the same layout.

Unfortunately tagging them wouldn’t be useful as there are only certain cards within a note that i need to suspend. Also the main problem isn’t suspending the cards but the mess that i would get in the note browser… About the javascript, i haven’t fully understood how that method would work but sounds promising; could you please explain it to me?

So your back template might look something like this:

{{FrontSide}}
<hr id=answer>
<div id="SomeField">{{SomeField}}</div>

If SomeField contained real information, this is fine. But in some cases, you want a reference to another note to be displayed in this place while still keeping SomeField empty because there is another card template with SomeField on the front side which you don’t want to be generated. (Just recapping your goal as I understood it so far.)
So we have to store this information somewhere else and add another field to your note called “References”. Using JSON, its content might look like this:

{ "SomeField": "see some other note" }

Here, “SomeField” is the Id of the HTML tag which contains {{SomeField}} and “see some other note” is some arbitrary information you want to be displayed there.
Added to the above back template, the following script copies the “Reference” information to the identified tags:

<div id="refs" style="display: none">{{References}}</div>
<script>
	var refStr = document.getElementById('refs').innerHTML;
	var refs = JSON.parse(refStr);
	for (var key in refs) {
		var target = document.getElementById(key);
		if (target) {
			target.innerHTML = refs[key];
		}
	} 
</script>

(We need the first line because JS can’t access field content directly.)
This should do the trick.

Disclaimer: I’m not a JS programmer. I just hack together what I find on Google until it meets my requirements. :slight_smile:

1 Like

Yes, it can! I haven’t tested it, but I guess var refs = JSON.parse("{{References}}"); should do the trick for you.

Edit: Unfortunately this doesn’t really work, according to the answers below. Sorry for the confusion!


@aPaci Do I understand you correctly that you want to create a bunch of cards that shall be suspended indefinitely and are just for reference? This feels weird to me; why don’t you use a different medium for this purpose?

If you really want to store a lot of information directly in Anki and you don’t want those cards to appear during regular reviews, would a subdeck be a possible solution for you? Just put all of these “unwanted” cards into a different deck and set new cards and reviews to 0.

It really can’t. What happens is that Anki replaces the field reference {{...}} with the field’s text.
That’s why your code won’t work: "{ "SomeField": "see some other note" }" is not a valid string literal.

2 Likes

You can hack your way around the quote-issue by using single quotes '{{...}}'.

This works as long as the field content doesn’t (see what I did there?)
contain single quotes. In german it actually works more reliably, but issues will inevitably arise anyway.