Is there a template engine for Node.js? [closed]

Is there a template engine for Node.js? [closed]

I’m experimenting with building an entire web application using Node.js. Is there a template engine similar to (for example) the Django template engine or the like that at least allows you to extend base templates?


Solution 1:

Check out the Node js modules wiki page. They have listed all the templating engines supporting node.js.

Solution 2:

You should be able to use mustache.js, if it doesn’t work send me the issues and I’ll get it fixed because I’m about to be using them in node.js anyway.

I know that it works without a DOM because a bunch of CouchDB standalone apps are using it in a Spidermonkey view server.

Solution 3:

If you like haml, but want something even better check out for node, I wrote haml.js as well 🙂

Solution 4:

There are new templating engines all the time.

underscore.js adds a lot of functional programming support to js, and has templating.

And just today I heard about this:

Solution 5:

You should take a look at node-asyncEJS, which is explicitly designed to take the asynchronous nature of node.js into account. It even allows async code blocks inside of the template.

Here an example form the documentation:

    <% ctx.hello = "World";  %>
    <title><%= "Hello " + ctx.hello %></title>

    <h1><%? setTimeout(function () { res.print("Async Header"); res.finish(); }, 2000)  %></h1>
    <p><%? setTimeout(function () { res.print("Body"); res.finish(); }, 1000)  %></p>


Solution 6:

You can try beardless (it’s inspired by weld/plates):

For example:

{ post:
  { title: "Next generation templating: Start shaving!"
  , text: "TL;DR You should really check out beardless!"
  , comments:
    [ {text: "Hey cool!"}
    , {text: "Really gotta check that out..."}  ]

Your template:

<h1 data-template="post.title"></h1>
<p data-template="post.text"></p>
  <div data-template="post.comments" class="comment">
    <p data-template="post.comments.text"></p>


<h1>Next generation templating: Start shaving!</h1>
<p>TL;DR You should really check out beardless!</p>
  <div class="comment">
    <p>Hey cool!</p>
  <div class="comment">
    <p>Really gotta check that out...</p>