> but I get errors when I put instances in an \edef.
The number of commands that work in an edef is vanishingly small;-)
Probably (instances of) templates could be (or perhaps already are!)
robust via the normal latex \protect mechanism, in which case they
should survive the latex equivalent of \edef which is
\[log in to unmask]
There is no way to make an instance of a template expandable in general
as the key setting in the template call are typically low level register
assignments in TeX, and they are not expandable.