Skip to content

Instantly share code, notes, and snippets.

@nowri
Forked from milesplit/zepto.template.js
Created May 28, 2013 15:01
Show Gist options
  • Save nowri/5663390 to your computer and use it in GitHub Desktop.
Save nowri/5663390 to your computer and use it in GitHub Desktop.
// Template
// (c) 2011 Jason Byrne, MileSplit
// May be freely distributed under the MIT license, with attribution.
//
// ** Usage **
//
// HTML:
// <script type="text/html" id="tmplArticle"><h1>${Title}</h1></script>
//
// JavaScript:
// $('#tmplArticle').tmpl(data).appendTo($item);
//
(function($){
$.fn.tmpl = function(d) {
var s = $(this[0]).html().trim();
if (d) {
for (k in d) {
s = s.replace(new RegExp('\\${' + k + '}', 'g'), d[k]);
}
}
return $(s);
};
})(Zepto);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment