Use $-based substitutions for templating

Gives a consistent way to mark placeholders, and gives an error if an
identifier is not found.