Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save emerson-pereira/33e905d2b54c6dced3b9c77ea8679fed to your computer and use it in GitHub Desktop.
Save emerson-pereira/33e905d2b54c6dced3b9c77ea8679fed to your computer and use it in GitHub Desktop.
// Template (.hbs)
var template = (function () {
var template = null;
$.ajax({
type: 'GET',
dataType: 'html',
async: false,
url: 'templates/template.hbs',
success: function(res) {
template = res;
console.log('***** HTML template retrieved with success *****');
}
});
return template;
})();
// Data (.json)
var ctx = (function () {
var data = null;
$.ajax({
type: 'GET',
dataType: 'json',
async: false,
url: 'data.json',
success: function(res) {
data = res;
console.log('***** data.json retrieved with success *****');
}
});
return data;
})();
var compiledTemplate = Handlebars.compile(template);
var finalMarkup = compiledTemplate(ctx);
$('#main-holder').html(finalMarkup);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment