Various applications of util.template

This is the first bunch for #1276. I'd like to resolve #1281 before doing more.