Refractor getTemplateName function to avoid issue when namespace is bigg...

...er than 3 entries.