Content dependent card (quantity) generation

The cloze note type generates a content-depended number of cards per note.
I was wondering whether anybody could direct me to the associated code (I can Python), give me a tip or tell me it’s impossible, in order to create a different kind of content-depended variable card generation notes.

The use-case I have in mind is the classic vocabulary learning, and concerns specifically with the case of non-injective meaning relationship. What I mean is the following.
The usual case is a one-to-one mapping from the source and target languages.
front <> back

But homonyms are not infrequent. Say our target language is emoji, and we have the word :smiley: which has three different meanings: smile, happy and cheerful.
Instead of having the two cards
:smiley: → smile, happy, cheerful.
smile, happy, cheerful. → :smiley:

I’d like to have four cards
:smiley: → smile, happy, cheerful.
smile → :smiley:
happy → :smiley:
cheerful → :smiley:

Generated from an annotation such as:
{{front:::smiley:}} {{back1::smile}} {{back2::happy}} {{back3::cheerful}}

Or:

front-field:
:smiley:
back-field:
{{back1::smile}} {{back2::happy}} {{back3::cheerful}}

Any ideas?
Thanks!
Mark

You can easily do this with extra fields, card types and conditionals.

Fields:

  1. Word: :smiley:.
  2. Meaning1: smile.
  3. Meaning2: happy.
  4. Meaning3: .

Card1 Front: {{Word}}

Card1 Back:

{{FrontSide}}

<hr id=answer>

{{meaning1}} {{meaning2}} {{meaning3}}

Card2 Front:

{{#meaning1}}
{{meaning1}}
{{/meaning1}}

Card2 Back:

{{FrontSide}}

<hr id=answer>

{{Word}}

The other two card types are similar to card 2.


This results in 3 cards generated:

  1. :smiley: → smile.
  2. smile → :smiley:.
  3. happy → :smiley:.
2 Likes

You can do this with clozes. Put the :smiley: into the “Front” field, and format the “Back” field with clozes as follows:

{{c1::}} {{c2::smile}} {{c3::happy}} {{c4::cheerful}}

(the first cloze is empty and serves as a placeholder for generating the single Front → Back card)

On the front template, use:

{{#c1}}
{{Front}}
{{/c1}}

{{^c1}}
{{cloze:Back}}
{{/c1}}

(this will show the content of the Front field on the first card, and the clozed Back on all subsequent cards)

Add the following to the Styling to hide all not clozed parts from the subsequent cards and to uncloze the clozed part:

.cloze-inactive {
	display:none;
}
.cloze {
	font-size: 0px;
}
.cloze::before {
	content: attr(data-cloze);
	font-size: 20px;
}

Similarly, on the back template, show either full content of the Back field or Front depending on the ordinal number of a card:

{{#c1}}
{{text:cloze:Back}}
{{/c1}}

{{^c1}}
{{Front}}
{{/c1}}
5 Likes

I’m not familiar with this syntax? Is therein the conditional? Show if and only if not empty?

My HTML is not very strong but it seems like this is it! I’d give it a try.

Thank you everyone!

1 Like
1 Like

Thank you!
Would it generate empty cards, though?

It wouldn’t.

1 Like

You’re welcome.

As sorata said, it wouldn’t generate empty cards if the the front evaluated to nothing (e.g. Meaning2 is empty). However, if you edit a card and remove a meaning, it will become empty and you would have to use the empty cards tool.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.