# Anki renders my card templates only once

**URL:** <https://forums.ankiweb.net/t/anki-renders-my-card-templates-only-once/23974>\
**Category:** Help\
**Created:** [October 17, 2022, 4:35pm UTC](https://forums.ankiweb.net/t/anki-renders-my-card-templates-only-once/23974 "2022-10-17T16:35:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PerchunPak](https://avatars.discourse-cdn.com/v4/letter/p/6a8cbe/32.png) [@PerchunPak](https://forums.ankiweb.net/u/PerchunPak)\
**Post date:** [October 17, 2022, 4:35pm UTC](https://forums.ankiweb.net/t/anki-renders-my-card-templates-only-once/23974/1 "2022-10-17T16:35:06Z")

</div>

I wrote some templates based on JS, but Anki render those only once. So, for example, my template appends `to` to word and changes the color of the page. It’s fine until you use `Show Answer` button, `to` disappears. And if continue to second car, there are no anymore `to` and custom color (the color stays from ~~previous~~ the first card).

Can reproduce it in Windows 11 (qt5 and qt6) and AnkiWeb, but not in AnkiDroid.

---

<div class="post-metadata">

**Author:** ![kleinerpirat](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/kleinerpirat/32/19863_2.png) [@kleinerpirat](https://forums.ankiweb.net/u/kleinerpirat)\
**Post date:** [October 17, 2022, 5:38pm UTC](https://forums.ankiweb.net/t/anki-renders-my-card-templates-only-once/23974/2 "2022-10-17T17:38:54Z")

</div>

You’re probably getting this SyntaxError:  
[Identifier has already been declared Error in JavaScript | bobbyhadz](https://bobbyhadz.com/blog/javascript-identifier-has-already-been-declared#:~:text=The%20%22Identifier%20has%20already%20been,single%20time%20in%20a%20scope).

Make sure to use `var` instead of `let` and `const` in the global scope (outside of functions) or wrap your scripts in IIFEs.

* * *

> [@Conditional formatting (with JavaScript) doesn't work anymore](https://forums.ankiweb.net/t/conditional-formatting-with-javascript-doesnt-work-anymore/16797/4):
>
> The \<script\> will be executed every time, you go to the next card, but in the same context. If you use a let assignment with the same identifier (quoteanswer in this case) multiple times, JavaScript will complain, that "quoteanswer has already been defined". However, with var, you’re allowed to redefine the variable. TLDR, because this is valid JS: var a = 5; var a = 10; // OK: a is now 10 but this is not: let a = 5; let a = 10; // ERROR: a has already been defined

---

<div class="post-metadata">

**Author:** ![PerchunPak](https://avatars.discourse-cdn.com/v4/letter/p/6a8cbe/32.png) [@PerchunPak](https://forums.ankiweb.net/u/PerchunPak)\
**Post date:** [October 18, 2022, 5:05pm UTC](https://forums.ankiweb.net/t/anki-renders-my-card-templates-only-once/23974/3 "2022-10-18T17:05:31Z")

</div>

Replace all `let` and `const` on `var` helped! Thanks!

---

<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:** [May 1, 2023, 4:00am UTC](https://forums.ankiweb.net/t/anki-renders-my-card-templates-only-once/23974/4 "2023-05-01T04:00:30Z")

</div>


