Trimming templatedata keys

If templatedata exists, make sure keys are trimmed.
This came up because of a problem in hewiki, where an earlier "Template
Wizard" created templatedata but added a whitespace to all param keys in
that templatedata. This is done only if there is a need to (if
trailing/leading whitespaces are detected) to try and remain efficient.