Dynamic card type based on property value

hello.

have proposal / question.

what I’m interested in, is “dynamic card type” that depending on custom property evaluation (boolean value; basically same as search input) can display/hide fields.
(as side effect, large set of CSS changes can be also implemented in this way, but main focus of this proposal is Fields manipulation)

example of use-case:

  • I have imported deck(s) from sub-to-srs content
  • “front” is Audio; “back” is Sentence + Translation
  • if card was Matured – display Sentence on “front” and Sentence + Audio + Translation on “back”

high-level example of template

/* Front */
<if expression="prop:reps<6">
  {{Audio}}
  <else>
    {{kanji:Sentence}}
  </else>
</if>

/* Back */
{{furigana:Sentence}}
{{Translation}}
<if expression="prop:reps>5">
  {{Audio}}
</if>

or alternatively something like:

/* Front */
{{?dynamic-field-alias-id expression="prop:reps < 6"}}
  {{Audio}} /* if-clause */
{{:dynamic-field-alias-id}}
  {{kanji:Sentence}} /* else-clause */
{{/dynamic-field-alias-id}}

syntax, kind of ternary boolean expression: val x = expression ? on-true : on-false;

or just dynamic field support (but will potentially be open to case when “front” will become empty at some point)

{{$dynamic-field-name expression="..."}}

{{#dynamic-field-name}}
  {{Audio}} /* "audio" will be rendered if expression was evaluated to true */
{{/dynamic-field-name}}

in last case, “dynamic-field” declaration also may be moved out of Template into Fields form (as separate new type of field that supports expression)


alternatively choose (switch or when-when-then) syntax can be implemented instead of if-based
use-case, in mind: at first display Audio + Sentence on front; at some point switch to Audio-only; and then Sentence-only


notes:
I do understand that I can generate multiple carts from same note, but that’s 2x content
purpose of this functionality is that card may “scale” (demand more effort) as “familiarity” of content grows with time

If the specific custom property you’re interested in is reps you can create cards with this kind of functionality by using the JS API addon and the AnkiDroid JS API. The cards would then be compatible with desktop (requiring the user to install the addon too) and AnkiDroid but not AnkiMobile or AnkiWeb.

The APIs don’t give access to every property but there’s a couple other properties available in them that I could imagine one might want to change card content by:

  • interval
  • factor (this is also the FSRS difficulty)
  • flag
1 Like