[Help] Search & replace text in tags before displaying on cards

Hello,

Currently, I’m adding new words I learn from reading novels to Anki and using the tagging feature to record the title of the book in which I encounter each word. Ideally, I’d like to use spaces in tags, but since that isn’t allowed, I use underscores instead.

When I display those tags on the cards using the {{Tags}} field, I want to replace these underscores with spaces. I feel like this should be possible with JavaScript, but I wasn’t surprised to find out I couldn’t get it to work.

Could someone help me create my desired template, i.e. display the cards’ tag This_is_a_Book_Title as This is a Book Title on the card?

Thank you in advance!

Does the following works for you?

<div id="tags">
  {{Tags}}
</div>

<script>
  tagsEl = document.getElementById('tags');
  tagsEl.innerText = tagsEl.innerText.replaceAll("_"," ");
</script>
1 Like

Hello Eltaurus,

I just tried it and it indeed worked perfectly for me. Thank you for your help! <3

1 Like

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