Remove trailing whitespace from templates

Closes #1045.