Anki Forums

Relax or allow overriding template checks

The computer version of Anki recently introduced some checks upon saving of templates, intended to avoid common pitfalls when creating cards: Template checks by RumovZ · Pull Request #1200 · ankitects/anki · GitHub

One of these checks disallows saving if it is detected that there is more than one template with the same front side:
Screenshot_2

I have a use-case where I pre-generate cards with genanki and update them over long periods of time; to avoid having to create multiple different note types when I want to add a new card, I pre-create 10s of empty templates that then I update as I want to. As long as I just change the content of the template and not the name of it or the ordering, the notes update seamlessly using the same note type, even when I export this for other users. However, these new checks prevent me from editing a template because I have many empty templates, which is intended.

Is there any chance that we could allow a way for editing in this case? Potential ways that this could be accomplished that come to mind:

  • allow the user to override the checks (instead of “OK” being the only option, there could be an “Ignore” or “Override” option);
  • do not run the duplicate template detection logic on empty / blank templates
  • remove the detection altogether

Empty templates are also not allowed as at least one field replacement is required on the front side. From my point of view, this probably rare use case isn’t a good enough reason to remove these checks.
I don’t quite understand why you need to create empty templates in advance, but can’t you just populate them with some placeholder text? This would work for example:

TEMPLATE #XY
{{Tags}}

The reason to pre-create empty templates in advance is so that when I want to update an existing note type that users already have in their Anki database, I can update the note type seamlessly without causing an incompatible import to create a separate note type. For example, say I have field A and B and template X and Y. If I want to create another template Z and add it to the note type, users with the existing note that only include templates X and Y would receive a brand new note type, since there is a mismatch in the number of templates. By pre-creating many empty templates, I can update the templates at a later date and retain the desirable single-note property.

In fact, empty (and duplicate) templates are allowed on import of an apkg file. If we don’t want to provide a fix for my original issue, I would just suggest that we don’t integrate these checks into the import process. As it is now, I can still use genanki with this approach as that bypasses the checks from the above PR.

The reason to avoid adding placeholder text is because I don’t want the empty templates to actually cause cards to be generated (yet). Perhaps I could use an unused field to conditionally not generate these cards, but that feels like a pretty odd work-around at that point if I understand your suggestion correctly.

(Extra template, currently empty):

{{#Unused Field}}
Extra Template N
{{/Unused Field}}

Thanks for elaborating. I would have thought that you can update the notetype even if it has different fields, provided it has the same id. If you can’t, maybe that’s the actual problem? Would it be possible to improve this, @dae?

As for the workaround, you don’t need an extra field, the following will never create any cards:

TEMPLATE #XY
{{#Tags}}{{^Tags}}{{Tags}}{{/Tags}}{{/Tags}}

(Yes, it’s odd, but it works.)


As an afterthought, here is a better placeholder text:
{{^Card}}{{Card}}{{/Card}}

IIRC the duplicate comparison is an exact text match, so it should be sufficient to change add/change a single character on the template, eg adding a number to the end of each duplicate you want to keep. Literal text in the card template should not affect whether cards are generated or not.

The importing code will get an update soon, and hopefully it will allow changes to note types as part of the changes.

Templates without any replacement tag on the front side are also invalid, though.

I would be in favor of making the template checks optional. They can get really annoying if you know what you’re doing, e.g. when you add card templates with new field tags before creating the matching fields.

I also get errors with Asset Manager due to the new checks: Asset Manager [Official support] - #31 by kleinerpirat


Un-skippable, unnecessary error messages feel super limiting and I don’t see any benefit for experienced users. An option to disable the checks would be great.