Skip to content

Instantly share code, notes, and snippets.

@oobleck
Created March 9, 2014 02:59
Show Gist options
  • Save oobleck/9442312 to your computer and use it in GitHub Desktop.
Save oobleck/9442312 to your computer and use it in GitHub Desktop.
jQuery plugin: Itty bitty JS templating form Thomas Fuchs, v0.1
;(function(win, doc, undefined) {
'use strict';
var pluginName = 'tmpl';
// http://mir.aculo.us/2011/03/09/little-helpers-a-tweet-sized-javascript-templating-engine/
// Exposing this for global use, just in case.
window.tmpl = function tmpl(s, d) {
for (var p in d) {
s = s.replace(new RegExp('{'+p+'}','g'), d[p]);
}
return s;
};
// Only works on single elements
$.fn[pluginName] = function(data) {
var $this = $(this);
return tmpl($this.html(), data);
};
}(this, this.document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment