Putting Anki "code" in an external file

Folks,

Is there any way to reference in cards Anki “code” (CSS plus field references) contained in an external file? It seems from this thread that there must be: Put code in external text file. But I can’t tell from the thread how this works. Could someone explain that?

The background is this. I like to have on my cards info in addition to the answer. The reason for this is that the question that a card presents sometimes triggers a further question in my mind that I want to answer immediately in order to drive the point home/connect it with the current question/answer. I put this information in hints to hide it if I don’t need it. So, if I’m learning a language, I might have cards that look like this:

<div class=notestyle> 
  {{#Pronunciation}} 
    <br> 
      {{hint: tts en_us speed=1.0:Pronunciation}} 
    <br> 
  {{/Pronunciation}} 
  
  {{#Definition} 
    <br> 
      {{hint:Definition}} 
    <br>
  {{/Definition}} 
</div>

Note that the fields referred to don’t change from card to card.

Sometimes this “code” needs to be changed or expanded. I can do that using a mass replace for all cards containing it, but that’s a bit dangerous. What if I get it wrong? I could create quite a mess. So, what I would prefer to do is to be able to refer in each card of this type to an external file containing the “code”, which is the same for each card of the type, and then modify the “code” in that file as needed.

Thanks for any help you can give.

CSS/JS can be placed in an external file, but field references must be placed directly in the template.

1 Like

Aha. That’s good to know, and I’ll keep it in mind. I presume that the manual has that info, and I’ve just missed it. I’d like to suggest, though, that if it’s technically possible, allowing fields to be put in external files along with Anki logic (e.g., {{#Field}}) and CSS would come in very handy for some of us. I suppose I’m reiterating to some degree this suggestion: Store card template files as HTML and CSS in external folder .

Thanks again for your answer and the speed with which you provided it.

Keep up the great work!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.