Enhanced template engine