Created
January 8, 2013 12:06
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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