Future plans for nunjucks?
Extarys opened this issue · comments
I love using nunjucks, but every other templating engine still receive some attentions.
I would hate to see this project die. Are there any plans to merge some PR at some point?
On the homepage, they still feature "Firefox Marketplace" as "someone who uses nunjucks".
+1 for this, I'm still using nunjucks quite heavily. Partially out of habit but it also has lots of features I haven't seen elsewhere, using blocks and extend is just amazing!
+1 as well. The source code should probably be modernized (eg with classes, awaits, Typescript etc) to help it keep up.
+1 it is the best html templating engine.
Please, don't drop the maintaining.
I've been working on nunjucks "v4" off and on for quite some time now. It is structured as a monorepo, with the parser, compiler, and runtime in separate packages. The biggest change is that the compiler generates javascript AST rather than raw strings (though nunjucks.render
and nunjucks.renderString
generate strings from the AST). That should make the parser and compiler more flexible, opening the door for more easily adding functionality via plugins. The other big under-the-hood change is that most things are now generators that yield instead of return, which is a prerequisite for things like recursive loops, and makes it easier to support async/await everywhere. It also allows the implementation to more closely follow Jinja2, which eliminates a whole class of bugs. Basically, it's a complete rewrite. So far I've finished the lexer and parser, and have the compiler maybe halfway done.
That said, I don't want to over-promise anything. Work and family life take up a lot of my time, and we don't use nunjucks as much at The Atlantic, so I have to work on it on my own time. If anyone is interested in helping to get v4 to a place where it can become a public beta, please reply here or send me an email at fdintino@gmail.com.
I really want a modern Promises-oriented version that doesn't use asyncFor etc so I've spent the last couple of weeks implementing one. Its almost done, although there are a few tests still to get working.
I've part-way converted the implementation to Typescript as well, mucked around with the code formatting, ripped some stuff out, etc as I felt I needed all the help I could get to get things done. The fork is here https://github.com/benbriedis/nunjucksBB if you want to have a look. It might be possible to merge the two pieces of work together somehow if you think it would be useful.
I'm also pressed for time and really have to get a project out the door, but I could probably find a bit bit more time to get things done.
still receive some attentions
Meanwhile, there was a new PR just last week.
Any news?
no news, do you guys know any better and modern alternative ?
I can highly recommend Vento!
thank you for the recommendation. It's really good alternative.
I'll add the support for VentoJS to html-bundler-webpack-plugin.
If you're doing much work in Javascript then you should consider JSX, and in particular TSX (i.e. JSX with Typescript). This means using React, Solid, Preact, or perhaps using something like MorphDOM. TSX is less of a templating language and more, as the name suggests, 'extended' Typescript. This brings some big advantages:
- Great IDE support: you can use convenient tools to jump around your code. It will give you good hints and auto-completion. It will show you errors immediately. Your code is type checked.
- You can use the Typescript build tools - which have good error messages, can include incremental compilation, and there are various bundlers available.
- You have ready access to all JS functions and syntax
- Its very well supported.
The level of support is a result of the fact it is basically javascript, and any other templating language will have difficulty providing a developer experience that is as good. As Vento is tied to Deno, maybe they have a chance. To date Vue has been the main competitor to React in Javascript land.
The main disadvantages of JSX/TSX are that its a bit ugly, it is not a strong sandbox in the same way as a templating language, and there is more to learn.
@benbriedis for React, Solid, Preact etc - of course that would be JSX not much options left there.
I am looking for easy to use not overly complicated backend template engine for NodeJS (Javascript). Just tired of reactivity and excessive unneeded complexity of React like libs. Want to try HTMX, but for that I need a great html generation on the backend
I am looking for easy to use not overly complicated backend template engine for NodeJS (Javascript).
I can highly recommend Vento!
After trying many template engines I migrated all projects to Vento maybe half a year and never looked back. It’s simple, modern, well maintained and easily extendable with a few lines of JS.
Vento can be used in Deno and Node projects.
The author describes the advantages and disadvantages of other template engines including Nunjucks. Vento is the result of this investigation.
I’m not trying to convince you; but according to what you wrote Vento seems to be a good fit 😉
@Brixy ok, definitely will have a look at Vento!
If you were to compare Vento vs Twig, how would you describe pros & cons?
If you were to compare Vento vs Twig, how would you describe pros & cons?
Twig was not on my list. Maybe someone else can compare these two?!
I came from Nunjucks and Liquid, then tried the ones listed on Vento website + pug (just a bit), some others I probably forgot about, HTMX and JSX. Also played with WebC which is also very interesting. But I really prefer a language that just extends HTML.
Vento’s syntax is great, and you can pipe default JS or your own JS functions like
{{ "Hello, world!" |> toUpperCase }}
You can also write your own function within a Vento template
{{ function hello(name = "world") }}
Hello, {{ name }}!
{{ /function }}
{{ hello() }}
{{ hello("Vento") }}
I'm yet to try Htmx and Vento, but this gives me some homework to do :-)
@bora89 I believe it is possible to use TSX and JSX in a lightweight non-reactive fashion using 'h' - see https://www.typescriptlang.org/tsconfig#jsxFactory A warning though: I'm yet to try this myself. It should allow for an upgrade path in the future though should you need it.
@Brixy I used Twig in the past a lot. It has many 'extends' and 'includes' variants which seemed appealing to me at the time, but in practice they were unnecessarily heavyweight. I think you do better in Nunjucks just using 'set' commands and macros and end up with more maintainable code. Also its basically a PHP thing which complicates matters.
We deal with a lot of user driven input for these templates, so we currently run the templating inside isolated-vm
. We're probably going to take a look at liquid.js as that seems to be a little safer. Vento in this regard feels like a non starter, as the templates can execute native javascript, which is pretty scary. Maybe something to take into consideration?
This might be "too little, too late" for most, but fwiw I've finally got nunjucks v4 to a state where I felt comfortable making the repository public. There is a tracking ticket where I've listed the work that needs to be done. I welcome any and all assistance with completing the remaining work.