Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future plans for nunjucks? #1433

Open
Extarys opened this issue Jan 23, 2023 · 23 comments
Open

Future plans for nunjucks? #1433

Extarys opened this issue Jan 23, 2023 · 23 comments

Comments

@Extarys
Copy link

Extarys commented Jan 23, 2023

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".

@ext
Copy link

ext commented Jan 27, 2023

+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!

@benbriedis
Copy link

+1 as well. The source code should probably be modernized (eg with classes, awaits, Typescript etc) to help it keep up.

@webdiscus
Copy link

+1 it is the best html templating engine.
Please, don't drop the maintaining.

@fdintino
Copy link
Collaborator

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 [email protected].

@benbriedis
Copy link

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.

@OneCricketeer
Copy link

still receive some attentions

Meanwhile, there was a new PR just last week.

@Brandontam29
Copy link

Any news?

@bora89
Copy link

bora89 commented Feb 20, 2024

no news, do you guys know any better and modern alternative ?

@webdiscus
Copy link

no news, do you guys know any better and modern alternative ?

The alternatives:

  • Pug best of the best, supports the Partials and Layouts, but is not maintained over 3 years
  • TwigJS supports the Partials and Layouts
  • LiquidJS supports the Partials and Layouts

@Brixy
Copy link

Brixy commented Feb 20, 2024

I can highly recommend Vento!

@webdiscus
Copy link

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.

@benbriedis
Copy link

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:

  1. 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.
  2. You can use the Typescript build tools - which have good error messages, can include incremental compilation, and there are various bundlers available.
  3. You have ready access to all JS functions and syntax
  4. 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.

@bora89
Copy link

bora89 commented Feb 21, 2024

@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

@Brixy
Copy link

Brixy commented Feb 21, 2024

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 😉

@bora89
Copy link

bora89 commented Feb 21, 2024

@Brixy ok, definitely will have a look at Vento!

If you were to compare Vento vs Twig, how would you describe pros & cons?

@Brixy
Copy link

Brixy commented Feb 21, 2024

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") }}

@benbriedis
Copy link

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.

@benjdlambert
Copy link

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?

@fdintino
Copy link
Collaborator

fdintino commented Aug 1, 2024

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.

@Extarys
Copy link
Author

Extarys commented Aug 2, 2024

@fdintino It's never too little... Nunjucks template have its place IMO. Thank you for your time and effort <3

(I mainly use it for email/ticket templating and then basic standalone pages)

@robinmetral
Copy link

@fdintino sorry if I missed this, but can we get context on why you're moving development to a different org? Is Nunjucks no longer maintained by Mozilla? Are you the only maintainer left working on the project?

Again, apologies is this was mentioned elsewhere! Will follow development on v4 in the meantime 👀

@fdintino
Copy link
Collaborator

fdintino commented Aug 6, 2024

@robinmetral nunjucks hasn't been maintained by mozilla for quite a long time, since long before even I took over as maintainer. The idea behind the separate organization was that it could house other nunjucks-related projects. And also because there are organization-wide github repository settings that I can't change. If I want to use a github actions workflow that isn't already on the mozilla org allow-list I have to file a bugzilla ticket to get it added.

I am the only maintainer left working on nunjucks, and I haven't had much time to spend on it. It is much less critical to our projects at The Atlantic than it once was, so I mostly work on it on my own time. The majority of the v4 code was written two years ago, but I got swept up in other projects and it was left in a private repository in an unfinished state. Still, the fact that it existed made me less inclined to fix bugs in this repository, as they were generally fixed in my rewrite.

For the past few months I've made a push to finish the v4 work and get the project to a state where others could contribute. My goal is to eventually hand off maintenance of the project, and so I'll look to see whether there is a demand for the features in v4 and a community that would help maintain it. If there isn't, but people step forward who would help maintain this repository, I would be fine with that as well.

Edit: of course, if there was momentum behind the v4 repository, I would remain involved.

@robinmetral
Copy link

Thanks a million for the context @fdintino 🙌

It helps a lot, and your decisions make a lot of sense. I'll be following development on v4!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests