Refactored templating page renderer.

Following @jcheng5's peer review. Also distinguish unescaped HTML output from escaped in the default error template.