to make template compiler check happy

the "#" before "{" doesn't actually comment as it's not in the perl block yet.
thus we need to close the block by removing "#" before last "}".
I removed "#" before "{" too to make it more consistent.
strip out heading spaces when parsing template lines

to make it more tolerant in case user mis-types.