9

From what I've read, ExpressJS 3, dropped support of layouts, leaving it to the template engines. So if an engine, doesn't have a support for layouts, what's the best Node.js module that will have it? Or if best sounds subjective, not best but at least a working solution?

I'm going to use Hogan.js as a template engine.

Or, maybe there's a better alternative to layouts as a concept? I find it rather helpful but will like to read about other approaches.

C-Blu
  • 103
  • 1
  • 1
  • 5
  • generate project in terminal, jade is generate by default. I think jade is the first choice for express team (?) – damphat Dec 15 '13 at 07:54
  • Jade, even though is very readable, and it reminds me about slim and haml from ruby world, is said to be rather slow. This is why I'm trying other template engines. – C-Blu Dec 15 '13 at 07:57
  • I am not sure but for v8 engine, jade is faster hogan for those tests http://jsperf.com/dom-vs-innerhtml-based-templating/473 – damphat Dec 15 '13 at 08:51

3 Answers3

5

There are plenty of template engines.

Here are some good ones I know:

  • Handlebars - very good extention of {{mustache}}.
  • Jade - very powerfull template engine from visionmedia (the author of express.js) and my favorite one.
  • ejs - another template engine from visionmedia.

You'll find more engines here - in this question.

Community
  • 1
  • 1
Leonid Beschastny
  • 50,364
  • 10
  • 118
  • 122
  • Well I've started with jade by default, but read somewhere that it's not that fast compared to others. Maybe I will end up using it in the end. – C-Blu Dec 15 '13 at 08:00
  • don't use EJS, the docs aren't good and some functionality has been missing for over a year. –  Jan 25 '14 at 06:01
  • 1
    Yes Jade is said to be very slow, but it makes typing easy. If you're fine with using HTML the way it is or you actually prefer to do so, Handlebars is probably among the top suggestions. – Steen Schütt Mar 13 '14 at 14:33
  • I have been using Jade as it seems to be the goto template engine in the Node community. But have decided to switch to Handlebars. The shorthand notation of Jade is great, but becomes problematic when trying integrate normal HTML or namely SVG. Having to convert or escape blocks to Jade shorthand is a pain. Plus checking out Twitters Hogan.js looks promising for the frontend, can then keep consistent between server/browser. – Lex Jun 29 '14 at 03:23
4

You can take a look of the following templates that is supported in node.js:

https://github.com/joyent/node/wiki/modules#wiki-templating

Also this is benchmark that compares different types of templates according to thier rendering time

https://github.com/Deathspike/template-benchmark

My suggestion: ejs and jade is very powerful and have a lot of features and both are supported in express

Tareq Salah
  • 3,720
  • 4
  • 34
  • 48
1

I'm using express-ejs-layouts and works perfectly with underscore/lodash and ejs templates.

neiker
  • 8,887
  • 4
  • 29
  • 32