Generate a card in a deck only if a special field contain one character

General overview

Chinese note structure

I have a custom note named Chinese containing two fields:

  1. Hanzi (Chinese character(s))
  2. Pinyin (Standardized Latin translation)

Sometimes, a note can contain just one Hanzi, and sometimes it could contain a full sentence with multiple hanzis.


With Chinese notes two kinds of cards are generated. One named guess-the-pinyin (this one doesn’t occur any problem and it’s not really related to my question), and another one guess-stroke-order.

The problem

The guess-stroke-order card type should only be generated for notes witch Hanzi’s field contain one and only one symbol. Because guess-stroke-order bring a Maobi grid to draw the character. It’s not designed for multiple characters fields.

The question

How to conditionally generate guess-stroke-order when Hanzi field contain one and only one character?

I think you’d need to create a second note type for one-character words.

Anki’s templates have very limited forms of conditional logic. You can test if a field is empty or non-empty. But that’s all. See: Card Generation - Anki Manual (


While it is not possible to automate the process, if you wish to edit an already existing deck, it is relatively easy (or at least doable) to accomplish this using some workaround.

  1. Add a new field; for example, you could name it Add Stroke Order Card.
    Its purpose is to create a conditional replacement that controls whether the guess-stroke-order card is generated or not.

  2. Use the Browser + some regex to find all the notes that have only one Hanzi:
    e.g., note:Chinese -"Hanzi (Chinese character(s)):re:.{2}".

  3. Select all the search results, then use Find and Replace to fill their Add Stroke Order Card field with at least one character.
    For example, you can use these settings:

  4. Open the template editor, go to the guess-stroke-order card, than wrap the entire Front Template like this:

    This will ensure that the guess-stroke-order card is generated only when the Add Stroke Order Card field is non-empty.

  5. Go to Tools → Empty Cards to delete the guess-stroke-order card from all the notes that have two or more Hanzi.

It is always a good idea to create a Backup first.


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