6

In Anki I am trying to hide a third field if it is empty. This field is named Ref. In the styling view of a card, accessed by Edit > Cards, I have the following HTML snippet in the back template:

<a href="{{Ref}}">Link</a>

What I wish to know is how to hide the field if it is empty. There is the possibility to add Javascript to the card field, but there is no element inspector in the program.

approxiblue
  • 6,982
  • 16
  • 51
  • 59
mr_js
  • 949
  • 12
  • 29

2 Answers2

16

According to the anki manual, you can use conditionals with {{#Field}} ... {{/Field}} or {{^Field}} ... {{/Field}} to test if the field is blank or not. In your case, try something like this:

{{#Link}}
<a href="{{Ref}}">Link</a>
{{/Link}}

I haven't tested it, but it should work.

Edit: It's a bit late, but I realized I mixed up the names of the fields, and the Link field conditionals should have been called Ref:

{{#Ref}}
<a href="{{Ref}}">Link</a>
{{/Ref}}
M. Andres
  • 163
  • 5
2

What I ended up doing was the following:

{{#Ref}}<a href="{{Ref}}">Link</a>{{/Ref}}
approxiblue
  • 6,982
  • 16
  • 51
  • 59
mr_js
  • 949
  • 12
  • 29