开发者

Client side templates and partial views and express

开发者 https://www.devze.com 2023-02-23 04:37 出处:网络
We have a large amount of client side templating solutions recently including: jquery templates John resig micro templating

We have a large amount of client side templating solutions recently including:

  • jquery templates
  • John resig micro templating
  • handle bars
  • EJS
  • and more

As far as I can see only jQuery templates support the concept of partials 开发者_运维百科templates (in this case the {{tmpl}}).

What other templating engines allow for partial or nested templates?

I'm not an expert on express and I don't know how the partials work under the hood.

How do you integrate a non-standard templating engine into express ? (The standards are Jade or EJS).


Templating engines must provide a compile function.

https://github.com/visionmedia/express/blob/master/lib/view.js#L367

You can define the default templating engine by doing app.set('view engine', 'jqtpl') or let express guess from the file extension. Express will load automatically that engine by requiring it.

https://github.com/visionmedia/express/blob/master/lib/view/view.js#L122

You can see one example using markdown for example:

https://github.com/visionmedia/express/blob/master/examples/markdown/app.js


You might check out Knockout.js. It's an awesome data binding/templating solution that can re-render onscreen HTML on the fly by watching your data model.

http://knockoutjs.com/

http://channel9.msdn.com/Events/MIX/MIX11/FRM08

Supports nested templates (in a few different ways), attaching events to your templates, having compound template variables, and attaching your model objects to both input and output elements.

Way more flexible than the built-in jQuery templating, or other data binding options like Chain.js :)

0

精彩评论

暂无评论...
验证码 换一张
取 消