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

**URL:** <https://forums.ankiweb.net/t/what-is-the-best-way-to-make-a-variable-available-to-the-card-template/47159>\
**Category:** Development\
**Created:** [July 17, 2024, 6:05am UTC](https://forums.ankiweb.net/t/what-is-the-best-way-to-make-a-variable-available-to-the-card-template/47159 "2024-07-17T06:05:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomash95](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/tomash95/32/9335_2.png) [@tomash95](https://forums.ankiweb.net/u/tomash95)\
**Post date:** [July 17, 2024, 6:05am UTC](https://forums.ankiweb.net/t/what-is-the-best-way-to-make-a-variable-available-to-the-card-template/47159/1 "2024-07-17T06:05:39Z")

</div>

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

```python
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](https://addon-docs.ankiweb.net/reviewer-javascript.html), 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?

---

<div class="post-metadata">

**Author:** ![jhhr](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jhhr/32/21339_2.png) [@jhhr](https://forums.ankiweb.net/u/jhhr)\
**Post date:** [July 17, 2024, 9:16am UTC](https://forums.ankiweb.net/t/what-is-the-best-way-to-make-a-variable-available-to-the-card-template/47159/2 "2024-07-17T09:16:41Z")

</div>

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](https://ankiweb.net/shared/info/744725736) 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](https://github.com/ankitects/anki/blob/main/pylib/tools/genhooks.py#L63)
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](https://github.com/krmanik/AnkiJS-API/blob/main/anki-js-api-addon/ __init__.py) addon

---

<div class="post-metadata">

**Author:** ![tomash95](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/tomash95/32/9335_2.png) [@tomash95](https://forums.ankiweb.net/u/tomash95)\
**Post date:** [July 17, 2024, 3:51pm UTC](https://forums.ankiweb.net/t/what-is-the-best-way-to-make-a-variable-available-to-the-card-template/47159/3 "2024-07-17T15:51:30Z")

</div>

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. 😔

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [August 16, 2024, 3:51pm UTC](https://forums.ankiweb.net/t/what-is-the-best-way-to-make-a-variable-available-to-the-card-template/47159/4 "2024-08-16T15:51:58Z")

</div>

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