25

What would be a node.js templating library that is similar to Jinja2 in Python?

dreftymac
  • 31,404
  • 26
  • 119
  • 182
bodacydo
  • 75,521
  • 93
  • 229
  • 319
  • I would prefer [nunjucks](https://www.npmjs.com/package/nunjucks), as it was even *referred* by jinja2 – Jake Aug 19 '21 at 23:41

5 Answers5

33

https://mozilla.github.io/nunjucks

Nunjucks is basically a JS port of Jinja2

pederOverland
  • 860
  • 6
  • 8
6

Maybe a list of template engines for node.js can help here too.

List of template engines

  • Pug: Haml-inspired template engine (formerly Jade).
  • Haml.js: Haml implementation.
  • EJS: Embedded JavaScript template engine.
  • hbs: Adapter for Handlebars.js, an extension of Mustache.js template engine.
  • Squirrelly: Blazing-fast template engine that supports partials, helpers, custom tags, filters, and caching. Not white-space sensitive, works with any language.
  • Eta: Super-fast lightweight embedded JS template engine. Supports custom delimiters, async, whitespace control, partials, caching, plugins.
  • React: Renders React components on the server. It renders static markup and does not support mounting those views on the client.
  • combyne.js: A template engine that hopefully works the way you'd expect.
  • Nunjucks: Inspired by jinja/twig.
  • marko: A fast and lightweight HTML-based templating engine that compiles templates to CommonJS modules and supports streaming, async rendering and custom tags. (Renders directly to the HTTP response stream).
  • whiskers: Small, fast, mustachioed.
  • Blade: HTML Template Compiler, inspired by Jade & Haml.
  • Haml-Coffee: Haml templates where you can write inline CoffeeScript.
  • express-hbs: Handlebars with layouts, partials and blocks for express 3 from Barc.
  • express-handlebars: A Handlebars view engine for Express which doesn't suck.
  • express-views-dom: A DOM view engine for Express.
  • rivets-server: Render Rivets.js templates on the server.
  • LiquidJS: A simple, expressive and safe template engine.
  • express-tl: A template-literal engine implementation for Express.
  • Twing: First-class Twig engine for Node.js.
  • Sprightly: A very light-weight JS template engine (45 lines of code), that consists of all the bare-bones features that you want to see in a template engine.

(Some of these libs may be outdated or unmaintained.)

Source expressjs

zerocewl
  • 11,401
  • 6
  • 27
  • 53
4

jinja-js aims to fe a feature complete reimplementation of the jinja2 template engine in Javascript. To my understanding the other options mentioned here some of the many, many templating engine options available for Javascript.

vallentin
  • 23,478
  • 6
  • 59
  • 81
max
  • 29,122
  • 12
  • 52
  • 79
  • Recommendation requests for off-site resources or tools are off-topic on Stack Overflow. If you answer them, you specifically reinforce the belief that Stack Overflow is a good place to answer those questions. It is not. Please don't answer these questions even if you know a good answer as most answers will be highly opinionated ("I personally like..."). You can open the flag dialogue on the question and see the close reason in full under the **off-topic** category, or in the [help/on-topic]. You should also not even answer in a comment, as the effect is similar to an actual answer. – Kyll Nov 21 '15 at 13:59
1

Nunjucks & Swig

This 2 are similar Django, Jinja2, and Twig template engines.

kiril
  • 4,914
  • 1
  • 30
  • 40
Steely Wing
  • 16,239
  • 8
  • 58
  • 54
  • 2
    Swig is no longer maintained according to its github page https://github.com/paularmstrong/swig – kiril Sep 23 '16 at 01:38
1

The ejs is the npm module which you are looking for.

  • This is the name written in my package.json file --> "ejs": "^3.1.3"

  • EJS is a simple templating language that lets you generate HTML markup with plain JavaScript.(Credits: Ejs website)