# Anki 2.1.20: Updates to card template rendering

#### Damien Elmes

17 Jan, 2020 04:37 AM

The card template rendering process in Anki 2.1.20 has changed significantly under the hood, and most of the code that was in the anki/templates folder has gone away. Add-ons that were relying on hooks to modify the card rendering should continue to function, but add-ons that were using or monkey patching methods in the templates module will break, as those methods no longer exist.

I have looked through the add-ons on AnkiWeb that modify the card template, and believe most of them should be able to accomplish what they were doing before by using the new card_did_render and/or field_filter hooks. Examples of how each of them can be used are available here:

For add-ons that were using the furigana/hint field modifiers, they are available for copying in the template_legacy.py file.

If the hooks are insufficient for what your add-on is doing, please let me know within the next few weeks. If you're an end user and an add-on you use has broken, please let the add-on author know of this post.

• The limit of 100 replacements on a template has been dropped.
• The new approach allow add-ons to add fields without 'unknown field' messages appearing on mobile devices (once they've been updated)
• Fields with a ':' character are no longer allowed. If you have a ':' in your fields, you can open and close the Cards screen to automatically remove the colon.
• Templates that reference a field that doesn't exist will now only show an error, instead of partially rendering.
• {{field}} references are ignored inside fields, so there is no risk of LaTeX/MathJax being interpreted as a field reference.
• The <% %> alternate syntax is deprecated, as it is no longer necessary due to the above change.
• Clearer errors when the user forgets to close a {{field}} reference, or mismatches open and close conditionals.

If you have any feedback, please let me know.

1. Posted by arthur on 20 Jan, 2020 02:00 PM

I see you have introduced a way to let users know with which anki version an add-on as been tested. That's, really useful, thank you.
Is there any way to upload two distinct add-ons, depending on the version ? Or do I need to check version number to see which file I want to import when an add-on needs to change ?

2. Posted by lovac42 on 20 Jan, 2020 10:57 PM

@arthur, it is much better if you control the versions yourself. If a user zips up the addon and distributes it outside of ankiweb, the zipped package should work with anki regardless of version changes.

3. Support Staff Posted by Damien Elmes on 21 Jan, 2020 09:23 AM

I'll wager a fair few add-on authors don't want to have to go to the trouble of adding compatibility shims in and supporting multiple versions, so providing a way that authors can focus on the latest build while still providing an older build for users on old versions does make sense. The .ankiaddon manifest format also needs to be updated to support a version specifier as well.

4. Posted by arthur on 22 Jan, 2020 01:51 AM

This comment was split into a new discussion: Problems running from source

Thank you very much for taking this into consideration.

I've already received three bugs report related to beta. So I think that
updating the add-on is already going to take work, and it's far better
if I can simply concentrate on the new version.

Sadly, I have never been able to start github's beta on my computer
(ubuntu), which means I can't debug those add-on immediately.

Le 21/01/2020 à 01:23, Damien Elmes a écrit :

5. Posted by arthur on 22 Jan, 2020 12:09 PM

It has been removed from anki/init.py since 2.1.17 it seems.
I find the number in meta/version and in rspy/Cargo.toml, but I can't figure out how to access it.

As far as I can tell, meta/version is used only by the setup file. And I've no clue what is Cargo.

6. Support Staff Posted by Damien Elmes on 23 Jan, 2020 06:38 AM

'from anki import version' should still work.

7. Posted by arthur on 23 Jan, 2020 11:10 AM

Thanks

Le 22/01/2020 à 22:38, Damien Elmes a écrit :

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

### »

#### Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

# Keyboard shortcuts

### Generic

? Show this help Blurs the current field

### Comment Form

r Focus the comment reply box Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

## Recent Discussions

 17 Feb, 2020 08:05 AM Pasting selected formatting 17 Feb, 2020 08:02 AM "Improved Quizlet to Anki 2.1 Importer" Giving option to sign in for private Quizlet sets. 17 Feb, 2020 06:29 AM My app crashes when I review from a parent deck (Anki 2.0.58 (20058.1) iOS) 17 Feb, 2020 06:21 AM Not completely German 17 Feb, 2020 06:17 AM More updates to Anki's translations

## Recent Articles

 Text to speech support Card template has a problem Anki 2.0 support has ended Anki 2.0 add-ons Screenshots large and blurry on retina displays