views:

21472

answers:

14

I am looking for a template engine to use client side. I have been trying a few like jsRepeater and jQuery Templates. While they seem to work OK in FireFox they all seem to break down in IE7 when it comes down to rendering HTML tables.

I also took a look at MicrosoftAjaxTemplates.js (from http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16766) but turns out that has the same problem.

Any advice on other templating engines to use?

A: 

I'm totally satisfied with the XSLT/XML. It's main disadvantage it the learning curve: it took me about two weeks to understand the basics and a month to switch the developing to it

andy.gurin
Not really a fix for this.
knowncitizen
xml/xslt can also be used client side on some browsers to create templates
jujule
Only some browsers support it. And it doesn't really have a good mechanism for defaulting on browsers that don't support it. And JSON is a lot neater to ferry around than XML. And it's weird to get your head round. And there are some things that are really quite difficult to achieve in it, that would be easy in anything else. All counted, not a recommended solution to anything.
Marcus Downing
Just a thought, you can process/use Javascript in XSLT (at least in some, I am not knowlegable in all browsers on this point).
Mark Schultheiss
+10  A: 

Not sure how it handles your specific problem, but there's also the PURE template engine.

Christian Vest Hansen
besides its limitations, PURE is very easy to use
Jader Dias
@Jader, what limitations are the most painful?
Mic
@Mic PURE is limited by design. In server-side template engines you don't have to stick to valid HTML, but PURE is based on HTML. But I think there are quirks that would a allow another javascript template engine to be as powerful as the server side ones.
Jader Dias
@Jader, ok for HTML only. But I didn't get what do you mean by quirks and another engine.
Mic
@Mic PURE should have to be rewritten from scratch to allow some features to be included. To allow invalid HTML templates you should use `script` tags with attribute `type` different from `text/javascript`. This is one "quirk" that would allow invalid HTML.
Jader Dias
+3  A: 

This isn't jsquery specific, but here's a JS-based templating library released by google as open source:

http://code.google.com/p/google-jstemplate/

This allows using DOM elements as templates, and is re-entrant (in that the output of a template rendering is still a template that can be re-rendered with a different data model).

levik
+45  A: 

Check out Rick Strahl's recent post Client Templating with jQuery. He explores jTemplates, but then makes a better case for John Resig's micro-templating solution, even improving it some. Good comparisons, lots of samples.

ewbi
+1 for "Client Templating with jQuery"
Amr ElGarhy
http://github.com/jquery/jquery-tmpl is the actual repo of Resig's templating plugin.
Thr4wn
@Thr4wn, the source at the repro is significantly then the library discussed in the linked articles. Both by Resig though, sure.
Frank Schwieterman
@Frank "the source at the repro is significantly then the library discussed in the linked articles" Um huh? Say what? Not sure what you mean by this at all.
Mark Schultheiss
@Mark: he meant "significantly different than."
Domenic
+1  A: 

John Resig has one that's he's posted on his blog. http://ejohn.org/blog/javascript-micro-templating/

morgancodes
+1  A: 

If you're working in the .NET Framework 2.0/3.5, you should take a look at JBST as implemented by http://JsonFx.net. It has a client-side templating solution that has familiar JSP/ASP syntax but is precompiled at build-time for compact cache-able templates that don't need to be parsed at runtime. It works well with jQuery and other JavaScript libraries as the templates themselves are compiled to pure JavaScript.

McKAMEY
+7  A: 

jQuery Nano: http://github.com/trix/nano

Tomasz Mazur
+15  A: 

jQote: http://aefxx.com/jquery-plugins/jqote/

Someone took Resig's micro-templating solution and packaged it into a jQuery plugin.

I'll be using this until Resig releases his own (if he releases his own).

Thanks for the tip, ewbi.

KevBurnsJr
I actually just implemented this into production and it's working rather nicely
lomaxx
This has now become jQote2: http://aefxx.com/jquery-plugins/jqote2/
Alex Angas
A: 

hey i suggest you to use jquery ui templates from flashmint, saves some time and money. http://www.flashmint.com/show-type-jquery.html

jq
+1  A: 

I was using jtemplates jquery pluging but the performance was really bad. I switched to trimpath (http://code.google.com/p/trimpath/wiki/JavaScriptTemplates) which has much better performance. I haven't noticed any issues with IE7 or FF.

EShy
+20  A: 

Just did some research on this and I'll be using jquery-tmpl. Why?

  1. It's written by John Resig.
  2. It'll be maintained by the core jQuery team as an "official" plugin.
  3. It strikes a perfect balance between simplicity and functionality.
  4. It has a very clean and well thought out syntax.
  5. It HTML-encodes by default.
  6. It's highly extensible.

More here: http://forum.jquery.com/topic/templating-syntax

Todd Menier
+1. But I used Rick Strahl's. Bcoz it's a small one and serves my purpose well.
Ismail
it was just announced that this is now official plugin
serg
+2  A: 

Others have pointed jquery-tmpl, and I have upvoted those answer. But be sure to have a look at github forks.

There are important fixes out there and interesting features too. http://github.com/jquery/jquery-tmpl/network

Yann
Any particular fork to look at for fixes?
Kevin Hakanson
TBH, it's a bit messy...I went for http://github.com/appendto/jquery-tmpl after a quick scan on the changes and considering the fact that appendto is a company. YMMV
Yann
jquery-tmpl has been folded in the official 1.4.3 distribution.
Yann
+5  A: 

jQuery-tmpl will be in the jQuery core beginning in jQuery 1.5:

http://blog.jquery.com/2010/10/04/new-official-jquery-plugins-provide-templating-data-linking-and-globalization/

The official documentation is here:

http://api.jquery.com/category/plugins/templates/

jonsequitur