jQuery Templates
Similar to the macro-based templates in the popular javascript library Ext, jQuery templates offer ways of creating html chunks and applying an object of attributes to them via the jQuery DOM manipulation methods. Variable types default to JSP-style, however they can be customized to other variable styles for the plugin as well as for individual template objects. Via helper methods, variable functions can be applied to variables within the templates as well.
- Download jQuery Templates 1.0.0
- jQuery Templates Plugin Page
- Updates on Development
- Check out source code with Mercurial on BitBucket
Example Usage:
var t = $.template('
Hello ${name}, how are you ${question}? I am ${me:substr(0,10)}
'); $(selector).append( t , { name: 'Stan', question: 'feeling', me: 'doing quite well myself, thank you very much!' });
Another Example in Action:
var variables = { name: 'stan', day: 'today', long: 'really, really, really, really long string that will get truncated by the substring helper' }
The template text:
The template after it's magic:
(Yes, that was just done by the plugin!)
Find me on...
Shortened URL for this page: http://blog.stanlemon.net/25