Anki "watch" a HTML file as a card template

I’m thinking of making a card template with some UI functionality, and i would like to rapidly make small changes and see them in anki without repeatedly Ctrl+C Ctrl+V into a dummy card template. the main reason i didn’t just use my browser is because of the added bonus of anki easily syncing into ankiweb and ankidroid for testing, considering how different each of those platforms are. and i’m using various web technologies (partly for learning), so editing the card template inside anki isn’t viable.

so my question is, how to get a “card template watch” functionality for anki? i’ve thought of learning ankiconnect for this, but figured i’d search around and ask for help first.

for anyone who’s curious about what exactly my card template uses, i’m trying to build on top of Z233’s card templates on github. i’ve only just begun, but i would like to make prototyping my own UI easier.

You probably have to write an add-on (or a script that uses AnkiConnect) that watches for changes to the file and updates the template accordingly. Some useful links after brief googling:
python - How do I watch a file for changes? - Stack Overflow (Check out the Qt solution based on QFileSystemWatcher if you want to go for the add-on solution)
Watchdog — watchdog 0.8.2 documentation
GitHub - samuelcolvin/watchfiles: Simple, modern and high performance file watching and code reload in python.

2 Likes

Another option would be to externalize your JS into collection_media with a <script> tag and then symlink your project output.

You’ll only have to reopen the preview to see your changes.

4 Likes

i thought about linking <script> too, but i then realized i need to expose the field replacements manually instead of inside the project. ankiconnect seems to be my only option that builds on top of existing stuff. i’d hate to have another addon which can be eclipsed by other addons like ankiconnect. anyways, thanks @abdo and @kleinerpirat!