I want to style a field in Anki in which German articles are shown (der, die, das), and style it, so it shows blue for ´der´, red for ´die´and green for ´das´. I am using the desktop app and a basic note card type in anki, and display the articles on the back of the card.
I currently have 5 fields: Front > English, Back > Article, Singular, Plural, Image
This basic note has Front Template, Back Template and Styling sections. I pasted the code below in the Back Template section.
And got this answer of why it does not work:
Back template has a problem:
Found ‘{{/eq}}’, but expected ‘{{/eq ARTICLE ‘der’}}’
When I add the corresponding tags: /eq ARTICLE 'der, /eq ARTICLE 'die and /eq ARTICLE 'das, the problem persists and the error message does not change.
I think you are trying to use mustache template fragments in anki, but anki does not support that. You can learn more about anki field replacements here: Field Replacements - Anki Manual
Instead you can check for articles used on your card in javascript. Something like this should do the job:
I gave this code a try @NielegalneApfelschor, and it only displayed the first card in color, and then all in black. I also tried a workaround (second code) and it didn´t display any color at all. How come such a basic feature is so hard to implement?
Do you know what you are trying to use? You don’t need a mutation observer as the script you have on your card templates gets re-run every time a card gets show.
card renderer seems to reset classes sometimes after executing the javascript. Adding a short delay fixes it:
<script>(async()=>{
await new Promise(r => setTimeout(r, 5));
document.querySelector(".card").classList.add(`{{Reading}}`.trim().toLowerCase()+"Class")
})()</script>
Also remember to add styles to other articles (.dieClass, .dasClass) with your chosen colors.
Also, you are obviously using an AI chat bot that has no idea on how anki card rendering works. It would be helpful if you said so in your first post.