Suggestions for current jQuery template solution?
Asked Answered
T

4

9

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?

Tuscan answered 1/11, 2011 at 21:34 Comment(3)
api.jquery.com/category/plugins/templates (Read the Note:)Convertiplane
I have no experience with them but possibly something good on microjs.com/#templatingOzenfant
Looks like the tmpl author's working on the next alternative: JsRender. Use view source to see the rendering code. It looks the same as tmpl. His reasons for the change are here: borismoore.com/2011/10/….Caracalla
G
11

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

Grimy answered 26/11, 2011 at 21:56 Comment(1)
how do you compare jsRender vs DustJs ?Imogen
D
2
M
2

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.

Milldam answered 31/12, 2011 at 16:25 Comment(0)
U
0

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!

Underwater answered 30/5, 2017 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.