More card info in card template

Issue:


I am creating a shared deck and designing a custom card template. In the card preview a link will be shown which will be dynamicly generated with various info of the card and notes as url param so that user can report that card in my online portal.

let subdeck = encodeURIComponent('{{Subdeck}}');
let card = encodeURIComponent('{{Card}}');
let frontText = encodeURIComponent('{{Text}}');

let href =`http://127.0.0.1:5500/index.html?subdeck=${subdeck}&card=${card}&front=${frontText}&id=${cardId}`

Current approaches


So far i have found only limited filelds/variable can be used in the template like {{Card}} but I also need the note id and card id.

The two solutions i have found require me to install add-on.

Approach 01:

With this add-on many info can be access as like native ones.
https://ankiweb.net/shared/info/744725736

Approach 02:

javascript api bridge
https://ankiweb.net/shared/info/1490471827

pycmd("AnkiJS.ankiGetCardId()", (ret) => { console.log(ret); });

this works for Anki desktop and another thing to note is that this approach can also be used in ankidroid as they natively support a javascript API.

Approach 03:

By using a permanent uuid filed in the note itselt and passing it on to the link href.

https://ankiweb.net/shared/info/8897764
(lol: new user can only post two links)

Limitation/Problem


So my question is, is there any native way i can retrive info about a card in a card preview template without taking help from any addon? or is there any other way i can have a button placed in the card preview with that dynamic link?

Approach 03: Your own ID inside note

You don’t need an add-on to make the UUID approach work. It just means slightly more effort on whoever maintains/creates the notes. The only burden would be when adding notes, as simple as typing random numbers to create an ID (or preferably, automate this with an add-on like the one you linked). so, hypothetically, your link would be:

let subdeck = encodeURIComponent('{{Subdeck}}');
let card = encodeURIComponent('{{Card}}');
let frontText = encodeURIComponent('{{Text}}');
let myID = encodeURIComponent('{{MyID}}');

let href =`http://127.0.0.1:5500/index.html?subdeck=${subdeck}&card=${card}&front=${frontText}&id=${myID}`

Approach 04: Hash the entire note

Concatenate all fields into a single data stream, then hash it. that’s your ID without add-ons or making sure the notes have valid IDs. Users making notes would not need to do anything. This will be correct as long as notes on both your end and the other end (server? app? idk what you’re using this for.) creates the same hash. Exact duplicates will cause problems.

Unsolicited advice

you should to treat note fields containing user learning material as HTML. Or you risk errors from the user putting unexpected input that will escape the string. for example Lenz's Law equation: ? would break the string.

<template id="template-data">
<p>{{Text}}</p>
<p>{{Word}}</p>
<p>{{Meaning}}</p>
<p>{{Example}}</p>
<!-- and so on... in your script, parse the HTML to obtain your data. -->
</template>