Some years ago it seemed to me like JS template engines (Pug, Nunjucks & co.) were all the rage, but I haven't been hearing a lot about them lately?
Recently I went on YouTube to look for some materials on Pug/ Nunjucks/ Handlebars, and the majority of results I got were old stuff from around 2-4 years ago. I checked on Google Trends and searches for the phrase "template engine" seem to be gradually decreasing - and I'm not really seeing them in the requirements for frontend dev positions, either.
Is this because JS templating engines have been sidelined? Or is it just assumed now that every web dev will have had some experience with them? π€
Top comments (24)
Yes they are still relevant but maybe not as popular now because of the rise of javascript frameworks like React, Vue and Angular. And people typically start by learning a front-end language and framework before they move into back-end. I use
ejs
if I am working with node andJinja
if I am working in a Python/Flask environment.Thanks for the comment! I'm reading through some old discussions on this now, and it does seem like template engines have been at least partly superseded by frameworks.
Even so, I'm glad I took some time to learn Pug just out of curiosity. Popular or not, I still think template engines are kinda cool?
Yes they remain cool you could avoid using a javascript framework all together if you wanted to. It's good for working on small projects or quickly testing out some back-end code without having to set up a whole front-end framework.
*cries in Lua*
That's not "old"; there's no reason why everything should have to be renewed every half a year, when it already works well. Templating is one of these things where you can't really add lots of features. Once you're done, you're done. All you can do is refactor code and that usually doesn't require updating tutorials.
Yeah, I completely agree! My point isn't really that there is a need to update these materials in any way, but rather that when a technology is really popular, people will usually create a lot of new content about it whether there is a need or not :)
So I'm just using this as a gauge of "interest" in these engines.
Fair point :D
Hmmm good question. I would even say they will rise in popularity again because of the JAM Stack Trend. A lot of blog owners are migrating and trying to hit better Lighthouse Scores without any JS Framework and thats where Templating Languages are used very often. For example take eleventy (11ty.dev/docs/)... right now it hast support for 11 Templating Languages.
Ah, that's a good point - I have not considered that! I'm hearing more and more about JAMstack lately, it's probably time to look into it.
Any template engine is just an abstraction or a derivative product of HTML, so when the HTML spec changes the template engine becomes obsolete or redundant unless it gets updated. It's always better to stick to standards instead of hoping for maintainers to update a library, my honest opinion
You're generally right: a library is updated only as long as it's useful, and it's useful only as long as it's updated. But it's not entirely a closed circle π€
There were real benefits to using these standalone engines that we can't overlook - just as there are benefits to using other libraries now (thinking about React here). There is always a chance of something being superseded by newer tech, which is probably what's happening to these template engines at the moment, but I don't think that means you should avoid using libraries altogether. It's just a question of where you place your bets :)
After a couple of months, I'd like to add that JS template engines are usually targeted to MVC fullstack applications which are kind of NOT the point of using Node in the backend. It's much better to either go full JSON-only (as in APIs) or use something else for a fullstack MVC app, like PHP. In fact, PHP template engines are much more relevant and used compared to Node's.
I think with React server side rendering, template engines lost popularity.
Yeah, that's part of it probably!
Template languages are still very much relevant. Vue and Angular both used them.
Also, there are other use-cases besides web development. For example, at work I use Ansible which heavily relies on Jinja to template files. If you use Helm with K8s you also gonna use templating.
Hey, thanks for the comment! You're right - template engines will probably always be a part of larger frameworks. I guess in my post I was referring mainly to "standalone" JS template engines, since their popularity seems to have decreased a bit.
I think in the JS-world, frontend frameworks like Vue do most of the main work of template engines now. For small experiments without a huge framework I still use Handlebars.
(But if we're talking PHP development: Yep, still a thing!)
SSR and SSG are very trivial using a templating engine. On the other hand, you need some clever tricks or some "magic" in order to do the same with React. Depending on your use-cases, templating engines can be more appealing. Personally, I don't mind doing client-side rendering, so I use React most of the time.
Definitely with the popularity of frameworks, template engines are no longer used. frameworks are more fun to use! Despite this, lately I have realized that I have done projects with a framework, which surely would have been better approached with templates. Especially when it comes to ssr. And I'm not talking about small projects. The rendering on the server of the frameworks is not compared to that of the templates, the latter are more stable.
As others have noted, templates have largely been pushed into the JSX space. Also "template literals" as a native JavaScript feature make at least some template engine concepts unnecessary: developer.mozilla.org/en-US/docs/W...