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? 🤔
Latest comments (24)
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
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.
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 :)
Template engines are no longer popular nowadays because of the rise of front-end libraries and frameworks. But If we don't want to use any library/framework for designing simple front-end then template engines can be used. I have written an article explaining in detail how to create applications using ejs template engine in Node.js which you can check here
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...
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.
We use Jinja a lot, we have our own transpiler to generate Jinja templates and we build static websites and PDFs from those.
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.
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!)
ReactJS is the thing now! Check it out.
Is there anyone here to explain how can I build my template engine such as pug, ninjucks in any language.
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.