templating logic