Skip to content

Instantly share code, notes, and snippets.

@maxbeatty
Created July 27, 2012 18:16
Show Gist options
  • Save maxbeatty/3189524 to your computer and use it in GitHub Desktop.
Save maxbeatty/3189524 to your computer and use it in GitHub Desktop.
Sample Mustache templates
<div id="mustacheContainer"></div>​
// json1.js
var user = {
fname:'joe',
lname:'blogs',
}
// json2.js
var translations = {
someword:'its translation'
}
// test.mustache => https://gist.github.com/3189524
var extension = "html",
gistID = '3189524',
testMustacheGist = "/gh/gist/response." + extension + "/" + gistID + "/"
/*
$.get(testMustacheGist, function(templates) {
var template = $(templates).filter('#tpl-one').html();
$.extend(json1, json2);
var three = $(templates).filter('#tpl-three').html();
three = {
"tplThree": one
};
var html = Mustache.to_html(template, json1, three);
$('#confirmationMustacheContainer').html(html);
console.log(templates);
$('#mustacheContainer').text(templates);
}, extension); */
$.ajax({
url: testMustacheGist,
success: function(data, status, jqXHR) {
console.log(data, status, jqXHR);
},
dataType: 'html'
});​
<script id="tpl-one" type="text/html"><!--main template -->
{{fname}}
{{> tplThree}}
</script>
<script id="tpl-two" type="text/html">
{{lname}}
</script>
<script id="tpl-three" type="text/html">
{{> tplTwo}}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment