Different card templates for new/review cards using conditional tags?

is there anyway to selectively hide or show sections of a card depending on whether it is a new card or a review card? I would like new cards to show the translation of a word so I can learn it but then hide that translation once the card becomes a review card. I know how to hide and show things based on whether a field is populated, but I don’t know whether I can do the same based on whether the card is new or review.

1 Like

You can achieve this with the custom scheduler, although it’s a bit complicated. Here’s how you can do it:

( Note: In AnkiDroid, you may need to enable the New reviewer in the Developer options for this to work on the back of the card. I don’t own an iOS device, so I’m unsure if this works in AnkiMobile. )

Deck options → Custom scheduling

function getOriginalState(states) {
    let originalState = null;
    const current = states.current;
    if (current.hasOwnProperty("normal")) {
        originalState = current.normal;
    } else if (current.hasOwnProperty("filtered")) {
        originalState = current.filtered.rescheduling.originalState;
    }
    return originalState;
}

function getReviewState(states) {
    return ["new", "learning", "review", "relearning"].find((type) =>
        getOriginalState(states).hasOwnProperty(type)
    );
}

const reviewState = getReviewState(states);

// If the card is new, display elements with the "only-new-card" class on the front of the card
if (reviewState === "new") {
    document.querySelectorAll(".only-new-card").forEach((el) => el.hidden = false);
}

// Make the review state accessible from the card's back template
globalThis.cardReviewState = reviewState;

Front template

{{Front}}
<div class="only-new-card" hidden>
    <div>New Card</div>
    <div>{{field 01}}</div>
    <div>{{field 02}}</div>
</div>

Back template

{{Back}}
<div class="only-new-card" hidden>
    <div>New Card</div>
    <div>{{field 03}}</div>
    <div>{{field 04}}</div>
</div>

<script>
    if (globalThis.cardReviewState === "new") {
        document.querySelectorAll(".only-new-card").forEach((el) => (el.hidden = false));
    }
</script>

Related thread:

1 Like

If you would be satisfied with a simpler, manual solution, and you can trust yourself not to click on something that you don’t want to see anymore – Hint Fields are an option. Field Replacements - Anki Manual

Or – nearly as simple, still manual, no need to trust yourself :wink: – you can make 2 separate note types, the 1st with the translation, the 2nd without. You could (weekly?) search up cards/notes of the 1st note type that you’ve studied a minimum number of times, and Change Note Type for those to the 2nd type. Since the note types would be identical otherwise, your review history for each card would carry over to the cards on the 2nd note type.

1 Like

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