Use doctype class for ref classes
Make template vars actually work.
Add a test and improve the documentation. Closes #160