moved part of the templating logic from client to server