|
Documentation
Basic documentation for Simple Templates, a jQuery plug-in
IntroductionSimple Templates is a jQuery plug-in that provides an easy way to merge content within JavaScript. It is designed to work much like the built-in Template class in Prototype. Installation
Usage$('#my-div').html($.tmpl('<div class="#{my-class}">#{my-content}</div>', {'my-class': 'blue-headers', 'my-content': 'This is what I have to say!'}));Simple Templates works by searching your template string (the first parameter passed into $.tmpl) for tokens of the format #{some-identifier} and replacing them with corresponding keys from the values object (the second parameter). Here's another example: var myTemplate = "Hello #{name}. I hear you're feeling #{emotion}.";
var myValues = {
name : 'Joey Joe Joe',
emotion : 'like singing'
};
var myResult = $.tmpl(myTemplate, myValues);myResult now holds the string: Hello Joey Joe Joe. I hear you're feeling like singing. This little plugin ain't rocket science. Heck, it ain't even computer science. But, it filled a need for me and I hope you find it useful, too. Enjoy! |
Sign in to add a comment