Change template ext from php to phtml, add some functions to lib