Question

Jade is indeed very neat, but I personally dislike the syntax and look of it. Yeah, being able to write just :

body
  h1 Hello
  p This is 
    b bold

Thats cool and all, but I prefer the look and feel of HTML/XML still. It was made to be human and machine readable and overall I think it's easier to glance at and understand.

Are there any templating engines that work more like:

<body>
  <h1>{title}</h1>
  <p>{content}</p>
</body>

Using the same Jade like concept of:

res.render('index', {
  title:pageTitle,
  content:pageContent
});
Was it helpful?

Solution

Something that specifically looks like that would probably be Mustache for Node.js. Check the demo.

OTHER TIPS

Take a look at EJS. Allows you to use regular HTML and embed Javascript code.

For example:

<div>
<% if (foo) { %>
foo
<% }else { %>
bar
<% } %>
</div>

Also, what you're looking for is an "Express-compatible" templating engine, and EJS is Express-compatible. It's made by one of the main guys behind Express.

You can use straight HTML in Jade, give this a try:

<body>
  <h1>#{title}</h1>
  <p>#{content}</p>
</body>

Consider jQuery templates. You can provide your data in JSON and apply it to a template.

If you're already using underscore.js

var compiled = _.template("hello: <%= name %>");
compiled({name : 'moe'});
=> "hello: moe"

Templates can be only a matter of taste. I don't like Jade either and favouring HTML is a better option. Most of times, webdesign layouts cannot be easily converted to those templates.

the sample provided moustache:

<h1>{{header}}</h1>
{{#bug}}
{{/bug}}

{{#items}}
  {{#first}}
    <li><strong>{{name}}</strong></li>
  {{/first}}
  {{#link}}
    <li><a href="{{url}}">{{name}}</a></li>
  {{/link}}
{{/items}}

{{#empty}}
  <p>The list is empty.</p>
{{/empty}}

It can be mixed with Angular.js syntax... could be a problem for people using it.

I recommend a new template engine: Saker, it enables fluid coding workflow, unlike most template syntaxes, you do not need to interrupt your coding to explicitly denote server blocks within your HTML.
Github: https://github.com/eshengsky/saker

The code looks like:

<body>
    <h1>@title</h1>
    <p>@content</p>
</body>

I personally use Nunjucks with all of my Node JS projects for a few years now and still loving it. I switched from Swig because Swig was lacking in some of extensibility when a project became more complex.

I, too, am not a fan of Jade / Pug. I prefer normal HTML syntax and inject some custom templating schemes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top