Nunjucks templating by Mozilla

This post is more than 2 years old.

This is mainly just a FYI type post, but earlier this week I discovered Nunjucks, a client-side templating language by Mozilla. I've been pretty much sold on Handlebars as my template language, but Nunjucks has a lot going for it too. Out of the box it seems to support a lot more than Handlebars (inheritance and asynchronous support for example) and the template synax is as friendly as Handlebars'.

Of course, my only real requirement for template syntax is to not suck as bad as Jade but that's just me.

It supports client-side (obviously) and server-side (for Node) so it's ready to go pretty much anywhere. I'd love to see this supported in Harp in the future.

If you want to take it for a test drive, I built an online Nunjucks tester here: http://www.raymondcamden.com/demos/2014/oct/15/test.html. You can't test everything there of course (inheritance for example), but you can quickly test out some of the syntax and see how it feels.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Ryan posted on 10/15/2014 at 8:38 PM

I think it "does more" because it breaks out of the "logicless templating" that Mustache and Handlebars try to enforce. Eg; {% set ... %}

Reminds me of Angular's filters. {{ foo | replace("foo", "bar") | capitalize }}

Comment 2 by Raymond Camden posted on 10/15/2014 at 8:40 PM

Good point there Ryan.

Comment 3 by Brock Whitten posted on 10/16/2014 at 2:30 AM

Helpful post, thanks. Would you prefer Nunjucks over Handlebars in Harp?

Comment 4 by Raymond Camden posted on 10/16/2014 at 4:13 AM

I've used Handlbebars in real apps. I know it works. I've only looked at this this week. It definitely *seems* cooler, but I won't know till I use it for a real app.

Comment 5 by Edward Beckett posted on 10/25/2014 at 2:06 PM

Nunjucks looks pretty cool... I've been messing around with Dust.js [http://akdubya.github.io/du...] it's pretty awesome...

LinkedIn has a port of Dust.js they use on the front end they proclaim to have optimized for performance...

https://github.com/linkedin...

Comment 6 by Edward Beckett posted on 10/25/2014 at 2:12 PM

Here's a couple other cool links to check out the LinkedIn port of dust if you're interested...

http://linkedin.github.io/d...

http://linkedin.github.io/d...

Comment 7 by Raymond Camden posted on 10/26/2014 at 12:43 AM

I looked at Dust before - it just didn't impress me enough to really try it. To be clear, I'm not saying it looked bad, it just didn't impress me *over* Handlebars (unlike Nunjucks).