Skip to content

Instantly share code, notes, and snippets.

@uditalias
Created January 8, 2013 12:06
Show Gist options
  • Save uditalias/4483270 to your computer and use it in GitHub Desktop.
Save uditalias/4483270 to your computer and use it in GitHub Desktop.
A fix to Handlebars jQuery plugin from: http://blog.teamtreehouse.com/handlebars-js-part-3-tips-and-tricks. When using the original plugin, we must load our template from a <script> tag, if we want to load it from a JavaScript variable the problem is that the parent element of our template wont be included in the result. I changed the line: temp…
(function ($) {
var compiled = {};
$.fn.handlebars = function (template, data) {
if (template instanceof jQuery) {
template = $("<div />").append($(template).clone()).html();
}
compiled[template] = Handlebars.compile(template);
this.html(compiled[template](data));
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment