Reputation: 7959
I'm looking for a reliable jQuery templating engine.
I've been developing with jquery.tmpl.js, even though I knew it was abandoned. I've been able to achieve what I wanted with it but have some slight doubts about its cross-browser reliability.
For one thing, IE7 seems to be flagged up as a problem area, and I now don't want to go much further until I feel more confident that it can eventually be incorporated into a production solution.
There's healthy discussion on this StackOverflow question about templating, though sadly this is now out-dated.
The github repository for jquery.tmpl.js says that it's been moved to jQueryUI, but the jQueryUI site makes no mention of templating.
So does anyone have any good experience with templating in jQuery and/or can point me towards a reliable solution?
Upvotes: 9
Views: 1472
Reputation: 10047
I use my own solution: https://github.com/lingtalfi/cloneTemplate It's based on jquery. It's just a helper, not a full-featured templating solution. (Full code is about 30 lines)
The syntax is pretty straightforward:
var variables = {"marie": "mary"}; // this dumb/demo map will simply replace marie by mary
var jClone = $.fn.cloneTemplate(jTpl, variables);
It does the job of injecting variables into a template. The placeholders in the template look like this:
{-myTag-}
and
{-%myTag-}
for the htmlspecialchars version.
That's it!
Upvotes: 0
Reputation: 37524
Linkedin uses Dust. They wrote a decent article explaining how it helped them create a common UI from disparate back-end implementation approaches (JSP, Grails, Rails, etc.) It might be worth looking into.
Upvotes: 2
Reputation: 22338
JsRender is the replacement for jQuery Templates. jQuery Templates are no longer in development ... both jQuery and Boris Moore (driving force behind them) moved on to JsRender.
However, you can use jQuery templates because as of today, they are more stable than JsRender is. JsRender and JsViews is quickly coming and together they will do what jQuery templates does now. JsRender is has some advantages already over jQuery templates especially in terms of performance (its string based rendering engine does that).
You can find several examples by Boris Moore here: http://borismoore.github.com/jsrender/demos/step-by-step/index.html
Upvotes: 11
Reputation: 1221
Use JsRender - http://borismoore.github.com/jsrender/demos/step-by-step/index.html
Upvotes: 2