Templating with Javascript logic