Oscar Godson
Oscar Godson

Reputation: 32746

Templating Engine for Node that's NOT Jade

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
});

Upvotes: 10

Views: 3167

Answers (8)

Manny
Manny

Reputation: 6287

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.

Upvotes: 0

Sky
Sky

Reputation: 251

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>

Upvotes: 0

JBarros35
JBarros35

Reputation: 1026

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.

Upvotes: 0

Rudolf Meijering
Rudolf Meijering

Reputation: 1587

If you're already using underscore.js

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

Upvotes: 1

Jack
Jack

Reputation: 15872

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

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

Upvotes: 4

Jorge Israel Pe&#241;a
Jorge Israel Pe&#241;a

Reputation: 38616

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

Upvotes: 3

JSPP
JSPP

Reputation: 2803

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.

Upvotes: 4

Babak Naffas
Babak Naffas

Reputation: 12561

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

Upvotes: 1

Related Questions