/** * Load a template and put it in a container. * @param {String} templateUrl The absolute path to the template * @param {String} templateId The id of the chosen template * @param {jQuery} $templateContainer Empty container where the template will be placed in * @param {Object} viewData The data that is loaded in the template * * @TODO: this must be refactored to a wrapper function for Mustache */ function loadPage(templateUrl, templateId, $templateContainer, viewData) { var defer = new $.Deferred(); $.get(templateUrl, function(templates) { var template = $(templates).filter(templateId).html(); var output = M.render(template, viewData); $templateContainer.html(output); defer.resolve(); }); return defer.promise(); }