Simply put, I hate pug’s syntax. So, I have to questions,
Do Handlebars and/or EJs have the same functionality as pug? Could you make a comparison of them? I’ve been searching about but still I do not know much to draw my conclusions or pick one.
Regarding Template Engines in general, I would like to know how wide spread is there use, is it used to make “real life” sites or for prototyping? As for now it just feels like a work around to api’s calls, but since I’ve never implemented them, it is just my idea.
Yeah, it’s much of a muchness. You write some HTML with the bits you want replaced as variables – <p>{{ foo }}</p>. That’s the template, and to fill it in you run a function, giving it the template and the value, and it returns HTML. Some templating languages like Pug or HAML use a different, compact syntax to let you generate HTML without having to type all the angle brackets, some dont, like EJS or PHP. You won’t find many detailed comparisons of Pug/EJS/Handlebars because every one does the same trivial thing. Some may have extra bells and whistles, some may use a different syntax, but they’re all doing the same thing.
Basically every single website you’ve ever been on will be using one. It’s not in any way, shape, or form practical to write every page of every website just in HTML. Take for example a website for a large newspaper – there isn’t someone writing an HTML page for every single one of the millions of pages that are on that website. Or a large e-commerce shop, someone doesn’t write an HTML page for every single item in the shop
When you say that every web is using one Template engine I’m confused. I thought that for instance, pages done with js mostly use React, Angular or Vue for displaying dynamic content. I don’t know if that assumption is right, and if it is, are you considering them as template engines or you mean that almost every web is using one of these: EJs, pug, handlebears? If so, the what’s the usage extent of the later ones?
Well, if the server that serves the HTML is written in JS, then maybe it’s using Pug or EJS. If it’s written in PHP, then it’s using PHP as a template engine. If it’s using Ruby maybe it’s using ERB or HAML. If it’s using Python maybe it’s using Jinja. If it’s using Go, maybe it’s using Go’s built in templating language. If it’s using Java, it’s a Java template engine. And so on. If the logic to render the HTML is moved to the browser instead of HTML being sent down the pipe, and maybe it’s using React or Angular or whatever, those libraries are doing the templating.
Not every site uses EJS or Pug because those are templating for Node based JS applications, if the application uses a different language then a templating library written in that language is used. But the all do the same thing.
I think you should differentiate between the concept of templating and the implementation (e.g. pug, jade).
As already mentioned, literally every page out there uses the concept: I put in some content (e.g. a newspaper text, product data) and the template engine adds the layout etc.
Even if you just add data to an JS array and iterate over it and make it a HTML heading and paragraph, this uses the concept of templating.
Well the answer to that is how many applications/websites are backed with a Node server that serves HTML pages (not likely to be able to get an answer, but it is safe to say it’s a very large number). They need to use a JS-based templating language, because they’re JS apps.