Created
April 11, 2010 20:25
-
-
Save ericflo/363036 to your computer and use it in GitHub Desktop.
This file contains 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
<ul> | |
{{#tweets}} | |
<li>{{text}}</li> | |
{{/tweets}} | |
</ul> |
This file contains 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
$(document).ready(function() { | |
var view = {'items': [{"name": "Item1"}, {"name": "Item2"}, {"name": "Item3"}]}; | |
$.mustacheLoad('example.html', view, null, null, function(rendered) { | |
$('body').html(rendered); | |
}); | |
}); |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Mustache with AJAX loading support</title> | |
<script src="jquery-1.4.2.min.js"></script> | |
<script src="mustache.js"></script> | |
<script src="jquery.mustache.js"></script> | |
<script src="example.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains 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 templateCache = {}; | |
var mustacheLoad = function(templatePath, view, partials, sendFun, callback) { | |
var template = templateCache[templatePath]; | |
if(template) { | |
return callback(Mustache.to_html(template, view, partials, sendFun)); | |
} | |
$.ajax({ | |
'type': 'GET', | |
'url': templatePath, | |
'async': false, | |
'success': function(data, textStatus) { | |
templateCache[templatePath] = data; | |
callback(Mustache.to_html(data, view, partials, sendFun)); | |
} | |
}); | |
}; | |
$.mustache = Mustache.to_html; | |
$.mustacheLoad = mustacheLoad; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment