Fixes to template.php

Changed to php, made to conform with W3C standards, various corrections.