DEV Community

Are template engines still relevant in 2020?

rzeczuchy on October 28, 2020

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 la...
Collapse
 
andrewbaisden profile image
Andrew Baisden

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 and Jinja if I am working in a Python/Flask environment.

Collapse
 
rzeczuchy profile image
rzeczuchy

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?

Collapse
 
andrewbaisden profile image
Andrew Baisden

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.

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

old stuff from around 2-4 years ago.

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

Collapse
 
rzeczuchy profile image
rzeczuchy

That's not "old"; there's no reason why everything should have to be renewed every half a year, when it already works well.

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.

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Fair point :D

Collapse
 
muellercornelius profile image
Cornelius Müller

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.

Collapse
 
rzeczuchy profile image
rzeczuchy

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.

Collapse
 
alaindet profile image
Alain D'Ettorre

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

Collapse
 
rzeczuchy profile image
rzeczuchy

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 :)

Collapse
 
alaindet profile image
Alain D'Ettorre

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.

Collapse
 
xlpacman805 profile image
Johnny Meza

I think with React server side rendering, template engines lost popularity.

Collapse
 
rzeczuchy profile image
rzeczuchy

Yeah, that's part of it probably!

Collapse
 
hi_artem profile image
Artem • Edited

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.

Collapse
 
rzeczuchy profile image
rzeczuchy

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.

Collapse
 
dianawebdev profile image
Diana

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

Collapse
 
0916dhkim profile image
Danny Kim

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.

Collapse
 
tojacob profile image
Jacob Samuel G.

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.

Collapse
 
ao5357 profile image
Brad Czerniak

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

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

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

Collapse
 
wclayferguson profile image
Clay Ferguson • Edited

Here's one new approach (link below) based on React (without JSX). I believe in the future everything will be pure TypeScript-generated DOM elements. There's no reason really to use templates any more. It's too much unnecessary 'friction'. Why bother with a template language's conditionals, looping constructs, and binding when TypeScript can do it all and MUCH simpler.

example of my login dialog (It's template free):

github.com/Clay-Ferguson/quantizr/...

BTW: Here's a site that's running that platform/code:
quanta.wiki

Collapse
 
itachiuchiha profile image
Itachi Uchiha

Is there anyone here to explain how can I build my template engine such as pug, ninjucks in any language.

Collapse
 
ivan_jrmc profile image
Ivan Jeremic

ReactJS is the thing now! Check it out.

Collapse
 
gualtierofr profile image
Gualtiero Frigerio

We use Jinja a lot, we have our own transpiler to generate Jinja templates and we build static websites and PDFs from those.