What is the best way to make a variable available to the card template?

I want to create a simple addon that lets you peek at your upcoming review queue:

from aqt import gui_hooks
from aqt import mw
from anki.cards import Card
from google.protobuf.json_format import MessageToDict

def peek_queue(card: Card):
    sched = mw.col.sched.get_queued_cards(fetch_limit=10)
    d = MessageToDict(sched)
    note_ids = [card['card']['noteId'] for card in d['cards']]
    upcoming = [mw.col.get_note(int(note_id))['field']
                for note_id in note_ids]

gui_hooks.reviewer_did_show_question.append(peek_queue)

upcoming is an array of whatever is in field. I want to make this available to the card template so that it can be displayed however you want to code it. I’ve thought of adding JS to the template with the variable available as per the dev guide, but I thought it would be nicer to somehow edit the note before it’s displayed so that this information is accessible as a field, i.e., {{next_hint}} or something. Is this possible?

1 Like

There’s two options:

  1. Make the variable available as a field like {{next_hint:}} (note the : at the end) in the same way the Additional Card Fields addon does it. The addon’s github repo isn’t available so you need to download the addon and the read the source from your addons folder to see how it’s doing it. Relevant: field_filter hook definition
  2. Make the variable available as the return value of calling pycmd("next_hint") in javascript within the card template. An example of adding additional pycmd arguments is the AnkiDroid JS API addon
4 Likes

Thanks for your reply. I got it working, but it turns out my idea wasn’t so useful after all. Surprising no one, seeing the upcoming prompt doesn’t make reviews go faster since you’ve gotta context switch to read them both … If only I had another set of eyes. :pensive:

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