Skip to content

Instantly share code, notes, and snippets.

@phiggins42
Created July 13, 2010 19:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phiggins42/474401 to your computer and use it in GitHub Desktop.
Save phiggins42/474401 to your computer and use it in GitHub Desktop.
dojo.provide("dojox.mustache._Templated");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
//
// INSTALL: copy http://github.com/janl/mustache.js to this folder as _base.js
// Add dojox.mustache = dojo.hitch(Mustache, "to_html") in _base.js, wrapping
// the whole file in a self-executing-anonymous-function. eg:
//
// dojo.provide("dojox.mustache._base");
// (function(){
// /* contents of Mustache.js */
// // export to Dojo
// dojox.mustache = dojo.hitch(Mustache, "to_html");
// })();
//
dojo.require("dojox.mustache._base");
dojo.declare("dojox.mustache._Widget", [dijit._Widget, dijit._Templated], {
// prevent from reusing DOM nodes as template, we want to redraw
_skipNodeCache:true,
_stringRepl: function(template){
// override the default/basic ${foo} substitution in _Templated
return dojo.trim(dojox.mustache(template, this)); // String
}
});
<!DOCTYPE html>
<html>
<head>
<script src="../../../dojo/dojo.js"></script>
<script src="../_Templated.js"></script>
<script>
dojo.ready(function(){
dojo.declare("my.Thinger", dojox.mustache._Widget, {
firstname:"dante",
lastname:"hicks",
templateString: dojo.cache("dojox.mustache.tests", "templates/whoami.html")
});
var body = dojo.body();
new my.Thinger().placeAt(body);
new my.Thinger({ firstname:"Peter", lastname:"Higgins" }).placeAt(body);
new my.Thinger({
name: "Peter Higgins".split(" "),
lastname: function(){
return this.name[1];
},
firstname: function(){
return this.name[0];
}
}).placeAt(body);
});
</script>
</head>
<body>
</body>
</html>
<p>Your name is: {{firstname}}, {{lastname}}</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment