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?
Join them; it only takes a minute:
closed as not constructive by Will Nov 28 '12 at 14:18As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question. |
|||||||||||||||||||||
|
|||||||||||||||||||||
|
Check out the Node js modules wiki page. They have listed all the templating engines supporting node.js. |
|||||||||||||
|
|
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. http://github.com/janl/mustache.js I know that it works without a DOM because a bunch of CouchDB standalone apps are using it in a Spidermonkey view server. |
|||||
|
|
If you like haml, but want something even better check out http://jade-lang.com for node, I wrote haml.js as well :) |
|||||||||
|
|
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: http://github.com/SamuraiJack/Shotenjin-Joosed |
|||||||||||||||||
|
|
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:
|
|||
|
|
|
You can try beardless (it's inspired by weld/plates): For example:
Your template:
Output:
|
|||||||||
|
|
I have done some work on a pretty complete port of the Django template language for Simon Willisons djangode project (Utilities functions for node.js that borrow some useful concepts from Django). See the documentation here. |
|||
|
|
|
I use Twig with Symfony and am now dabbling in node.js, so I'm looking at https://github.com/justjohn/twig.js and https://github.com/paularmstrong/swig, which you'll probably like if you use django. |
|||||||||
|
|
If you're looking for a minimalist approach to templates, you can check out JSON Template. A more full-featured alternative is EJS. It's a bit more similar to something you'd get from Django. Your mileage may vary for each of these - they're designed for a browser Javascript environment, and not Node.js. |
|||||
|
|
WARNING : JinJs is not maintained anymore. It is still working but not compatible with the lastest version of express. You could try using jinjs. It is a port of the Jinja, a very good Python templating system. You can install it with npm like this :
in template.tpl :
in your template.js :
The output will be :
We are actively developing it, a good documentation should come pretty soon. |
||||
|
|
|
I've heard good things about {dust} http://akdubya.github.com/dustjs/#dust |
|||
|
|
|
Try "vash" - asp.net mvc like razor syntax for node.js https://github.com/kirbysayshi/Vash also checkout: http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx
|
|||||
|
|
Google's Closure Templates is a natively-JavaScript templating system and a seemingly natural fit with NodeJS. Here are some instructions for integrating them. |
|||
|
|
|
haml is a good choice for node.js http://github.com/creationix/haml-js haml-js
html
|
|||
|
|
|
Did you try PURE ? While it was primarly designed for the browser, it works well with Jaxer and Rhino. I don't know node.js yet but if you can cache some JS and functions in memory, the speed should be even more impressive. |
|||||
|
|
There is a port of the Django templating engine to JavaScript. However, its not been updated for a long time but it may still have enough features. |
|||
|
|
|
Try Yajet too. ;-) It's a new one that I just released yesterday, but I'm using it for a while now and it's stable and fast (templates are compiled to a native JS function). It has IMO the best syntax possible for a template engine, and a rich feature set despite its small code size (8.5K minified). It has directives that allow you to introduce conditionals, iterate arrays/hashes, define reusable template components etc. |
|||||||||
|
|
I found hogan.js from Twitter and recommended by Tim O'Reilly on his site. I have no best practice with it, but I trust on Twitter and O'Reilly. You should try... |
|||
|
|
|
Here's a good evaluation of several engines http://engineering.linkedin.com/frontend/client-side-templating-throwdown-mustache-handlebars-dustjs-and-more |
|||
|
|
|
Honestly, the best and most simple template engine for Node.js is (IMHO) Plates (https://github.com/flatiron/plates). You might also want to check out the Flatiron MVC framework for Node.js (http://flatiron.org). |
|||
|
|
|
You can use dojox.dtl of DojoToolkit.org. Note that dojo 1.7 can well run on NodeJS and perform as a server side library. If you're interested, I can give you a simple example. |
|||
|
|