Rework template engine

This reworks the template from an eval/exec style (which sucked to work
with) to an eval/if/for style which is easier. It's still finicky on
whitespace, but it works good enough.