Anki cloze – type answer

Last Updated on July 27, 2022

Previously, I told you how to use a ready-made deck, how to set up your own cards, about useful functions. Next time I’ll tell you about automatic sound for your cards. And this time about Anki Cloze. And not simply Cloze, but with typing answer.

Cloze is a special note’s type. You can skip a word or some words or whole sentence. Programm show you a sentence with skipped places and you think, which words have to match.

In my cards I not only think, but also type words. It is great exercise for translation from native to foreign language.

It gives a lot:

  • the word is placed in context
  • you can train forms and prepositions
  • you can train meanings that are lost when we train a word without context. Many verbs have two or more very different meanings, each of which is often used in speech. But when studing a word, we study the first meaning well, and the second is often not learned or is forgotten.
  • you can study idioms

All posts about Anki
Part 1. Studying
Part 2. Editing a deck and notes
Part 3. Creating new notes
Part 4. Editing templates
Part 6. Add a pronunciation

This guide has been updated for Anki’s new design. The old version is not much different. For more important differences, the old version is hidden under spoilers. In the new version, you can click the “Downgrade” button in the “Profiles” window. But in terms of design, the new version is better.

In contrast to the standard form, I added a code for typing words to the cloze cards. The standard form assumes only turning the card over. In the previous post, we added such a feature, but there was a default code that does not work in the cloze. Here I had to search in various forums, from where I got the working code. Don’t ask me what it means – I just copied it with copy-paste.

Set up a Anki cloze template

1. On the page that lists the decks, go to Tools / Manage Note Types. There we press Add: Cloze.

Select “Fields” on the right. In the window that opens, click Add and enter the names of the fields that we need.

I have three fields. One German, in which I make a gap (Satz_deu). The second is native language, from which I translate (Satz_Muttersprache). And then there is the third (Basic_word). It does not participate in studing, but it is necessary so that in the overview the cards are shown not by the first word of the sentence, but by the main word. This is bequem for sorting.

Basic information about templates read here: Editing templates

When we have entered the names of the fields, go to the Cards. There is only one card here and it looks like this.

Please note that the code should contain the field name that you entered in the previous step.

Old Version

New version Anki

Anki cloze type answer

Since not all the code is visible in the scan, I copy:

<div style='font-family: Arial; font-size: 20px;'>{{muttersprache}}<br><br><br></div>

{{type:cloze:deu}}{{cloze:deu}}

<script type="text/javascript">
var fields = [];
function updateMain()
{
    ///Updates the primary "typeans" textbox with the results of each textbox.
    ///Only used if there are multiple cloze deletions.
    var textbox = document.getElementById("typeans");
    var str = "";
    var previous = "";
    var maxLength = fields.length;
    for (var i = 0; i < maxLength; i++)
    {
        //add the comma beforehand instead of afterwards, this avoids the need to explicitly handle consolidating two consecutive fields with the same value.
        var toAdd = fields[i].value;
        var addComma = (i != 0 && toAdd != previous);
        if(addComma)
        {
            str += ", ";
        }

        if(toAdd == previous)
            continue; //do nothing if the same data is consecutive.
        str += toAdd;
        previous = toAdd;
    }

    textbox.value = str;
    return true;
}
mungeCloze = function()
{
    var textbox = document.getElementById("typeans")
    //clozes are blue elements of: [...] which we want to remove.
    var clozes = document.getElementsByClassName("cloze");

    if(textbox == null || clozes.length == 0)
        return;

    var needsWork = (clozes.length > 1);

    fields = [];
    if(!needsWork)
    {
        var cloze = clozes[0];
        if(cloze != null)
        {
            textbox.removeAttribute("class")

            var container = cloze.parentNode;
            container.insertBefore(textbox, cloze);
            container.removeChild(cloze);
            textbox.style.display = ""; //make visible.
        }

    }
    else
    {
        //Clone the textbox and insert it before the deletions: "[...]".
        var length = clozes.length;
        var originalTextbox = textbox;
        for (var i = 0; i < length; i++)
        {
            var cloze = clozes[i];
            if (cloze == null)
                continue;

            var textboxToReplace = originalTextbox.cloneNode(true);
            textboxToReplace.id = "typeans" + i;
            textboxToReplace.onkeyup = updateMain;

            var container = cloze.parentNode;
            container.insertBefore(textboxToReplace, cloze);
            fields.push(textboxToReplace);
        }
      
        //Once we've handled each cloze, remove it from the list so it will not be modified again.
        while(clozes.length > 0)
        {
            var toRemove = clozes[0];
            toRemove.parentNode.removeChild(toRemove);
        } 

        //We hide the textbox here. If we did this beforehand then .clone() would transfer this to the new textboxes.
        originalTextbox.style.display = "none";
    }
}
mungeCloze();
window.setTimeout(mungeCloze, 1000);
</script>

It was Front Template.

Now Back Template

And Styling:

.card
{
font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;
}
.cloze
{
    font-weight: bold;
    color: blue;
}
#typeans { width: 450px; }
center { display:inline; }
typeGood { background: lightgreen; }
.typeBad { background: pink; }
.typeMissed { background: pink; }

Make a note

Template is finished. Now we make a notes. We can copy sentences from all unsere textbooks or online-exercises.

How you can add a note – read here.

I gave in this post only a couple of images. Not forget to check type of note, deck, tags.

After you have written the sentence, highlight the place you want to skip. And click three dots. You see brackets {{ }} and c1:: This means, that you made a gap. Pink field – because I took a sentence, that I already have. Duplicates are shown below.

If I make two gaps, for example if I have a Perfekt form, then second gap will have a c2:: This must be changed to c1::, otherwise this card will be shown two times: first with first gap, then with second gap.


This is how it will look during training. Errors are highlighted in pink.

Other posts about Anki – #anki.
Part 1. Studying
Part 2. Editing a deck and notes
Part 3. Creating new notes
Part 4. Editing templates
Part 6. Add a pronunciation

Do you enjoy the site without cookies and maybe without ads? This means that I work for you at my own expense.
Perhaps you would like to support my work here.
Or change your cookie settings here. I don’t use personalized ads

Leave a comment

Email is not compulsory

Cookie Consent with Real Cookie Banner