Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery jquery-tmpl roadmap

For some reason the develpment jQuery templating plugin (jquery-tmpl) has been put on hold. From reading blog blog articles on the topic it seems that either it will be included again in the future or replaced by something with a different approach (e.g. jsRender & jsViews)

What would be the future proof way of implementing templating in jQuery? (Using beta stuff is ok)

like image 967
AyKarsi Avatar asked Mar 14 '12 09:03

AyKarsi


2 Answers

The long term strategy is to replace the template plugin with JsRender and JsViews. Both projects are nearing beta. My suggestion would be to use jquery-templates for now and then switch to JsRender when its released. The template syntax is similar so it shouldn't be difficult to switchover when the time comes. Someone will probably create a tool for updating templates automatically...

Check out:

https://github.com/BorisMoore/jsviews https://github.com/BorisMoore/jsrender

and

http://www.borismoore.com/2012/03/approaching-beta-whats-changing-in_06.html

like image 75
ladar Avatar answered Nov 16 '22 11:11

ladar


Frustratingly this question is now more than a year old and the situation hasn't really changed. JsViews and JsRender are a lot more powerful than jQuery-tmpl, but they're also no-longer dependent on jQuery and a much larger library in their own right.

The timeline for this project appears to be a mess: jQuery-tmpl was beta and 3rd party, Microsoft contributed it as part of the official jQuery project, then jQuery dropped it because they felt these official plug-ins were diluting what jQuery was about. At the time full templating support was going to be in 1.5, but then it wasn't. There is a jQueryUI project page, but it looks pretty dead, and nothing about templates in any subsequent jQuery release.

Basically, whatever templating library you want use it has nothing to do with any official jQuery or Microsoft release now.

To be honest I think JsViews has become a full MVVM framework rather than just a templating plug in. It looks pretty impressive, but it's not a simple or lightweight jQuery plug-in or an update of jQuery-tmpl.

If you want to 'future-proof' template development there appear to be two broad patterns of use emerging:

  1. Use data-* attributes. Examples include Knockout (which uses a data-bind attribute containing an expression) and jQuery loadTemplate. Fairly simple to implement but limited to data-bindings that can be represented as attributes of tags.

  2. Use 'moustaches' - { brackets. Examples include JsRender, jQuery-tmpl and Mustache. These are more powerful as you can data-bind any text in the template. These aren't consistent with each other - JsRender uses {{:, jQuery-tmpl uses ${, Mustache uses {{ and so on, but they also have different syntax for loops, ifs etc.

In the future I think one of these might become the standard, but in the meantime you can't really future proof as there isn't a single stable approach now.

Finally there is also the underscore.js option: their default is to use the same syntax as .Net (i.e. <%=) but that's confusing for developers, the IDE and the compiler when using .Net, which basically makes that default incompatible for .Net developers. You can change it to use whatever syntax you want by providing an alternate Regex. That's probably the most 'future proof' (don't change your syntax, change your template parser) but also restricts you on what optimisations you can use and make rich tools support difficult.

I think with this kind of decision it depends on context. If you just want to use a few templates in an existing project I think the best option is to use jQuery-tmpl but plan to maintain it in house with new jQuery versions. If you want to build a new application from scratch that uses a Javascript MVVM then I'd evaluate to more complete frameworks, but plan to stick with whatever you pick.

like image 38
Keith Avatar answered Nov 16 '22 10:11

Keith