BorisMoore / jquery-tmpl

The original official jQuery Templates plugin. This project was maintained by the jQuery team as an official jQuery plugin. It is no longer in active development, and has been superseded by JsRender.
3.23k stars 1.01k forks source link

Reverse Engineer Data Given HTML and Template? #122

Closed mysterycommand closed 13 years ago

mysterycommand commented 13 years ago

Hello,

Would it be possible to "pull" the data out of HTML given a template? For example, I have an HTML page, being generated by PHP. I want to use a progressive enhancement approach, so that the page "works" even without JS, but if JS is available I'd like to handle changes to data via AJAX, and update the page via jQuery.tmpl. My problem arises during the initial page "bootstrap" if you will … is it possible to draw data, or tmplItems from HTML given a template?

Otherwise, I fear I will have to have PHP render my HTML, and my JS models, and then re-draw the HTML as soon as any interaction happens … anyway, it seems to be both non-DRY, and potentially prone to quirks.

Thanks much, //Matt Hayes

BorisMoore commented 13 years ago

That is part of what JsViews is intended to allow: Rendering a template on the server, and activating in the client if js is enabled.

See http://www.borismoore.com/2011/04/jquery-bay-area-conference-presentation.html for some links, but be warned that this work is not yet documented or stable.. I'm working hard to get it to that point...

JsRender has no DOM dependency, but for running it on the server you still need jQuery. If you generate HTML through PHP rendering (without templates), yes you can still activate in the client. But this will not be possible with just jQuery Templates in the current form. Rather it will need the JsViews/JsRender implementation in the client. You need to have appropriate annotations in the rendered HTML - and those are not yet documented, so it is still a bit early to begin using this scenario.

mysterycommand commented 13 years ago

Thank you so much for your quick response … I'll check out the links, and eagerly anticipate the future!