there exists templating engines that run on both server and client - for example, google closure templates.