// Custom method to load handlebars.js templates from external files // https://berzniz.com/post/24743062344/handling-handlebarsjs-like-a-pro Handlebars.getTemplate = function(name) { if (Handlebars.templates === undefined || Handlebars.templates[name] === undefined) { $.ajax({ url : 'resources/' + name + '.handlebars', success : function(data) { if (Handlebars.templates === undefined) { Handlebars.templates = {}; } Handlebars.templates[name] = Handlebars.compile(data); }, async : false // This might throw some errors at runtime in the console. }); } return Handlebars.templates[name]; }; // Handlebars Templates loading/compiling var templates = { //'crew-template': Handlebars.compile(document.getElementById('crew-template').innerHTML), 'crew-template': Handlebars.getTemplate('crew-template'), //'expedition-template': Handlebars.compile(document.getElementById('expedition-template').innerHTML), 'expedition-template': Handlebars.getTemplate('expedition-template'), //'sojuz-template': Handlebars.compile(document.getElementById('sojuz-template').innerHTML), 'sojuz-template': Handlebars.getTemplate('sojuz-template'), };