Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the pros and cons of using a template engine like Jade?

I'm looking into developing a web app with Node.js. I'm coming from a PHP background where I didn't use a template engine (besides PHP itself) and I have always just written straight HTML. So, why should I or should I not use Jade or some other template engine?

like image 598
James Simpson Avatar asked Sep 13 '11 18:09

James Simpson


People also ask

What is the benefit of template engine?

A template engine enables you to use static template files in your application. At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an HTML file sent to the client. This approach makes it easier to design an HTML page.

What is Jade template engine?

Jade is a template engine for node. js and the default rendering engine for the Express web framework. It is a new, simplified language that compiles into HTML and is extremely useful for web developers. Jade is designed primarily for server-side templating in node.

What is one of the benefits of template rendering?

Using a template engine makes it easy to separate out what's being displayed from how it's being displayed.

What is the best templating engine?

Mustache. Mustache is one of the most widely known templating systems that works for a number of programming languages, including JavaScript, Node. js, PHP, and many others. Because Mustache is a logic-less templating engine, it can be literally used for any kind of development work.


2 Answers

Pros:

  • Encourages good code organization (data generation is separate from presentation code)
  • Output generation is more expressive (template syntax doesn't require a sea of string concatenation)
  • Better productivity (common problems such as output encoding, iterating, conditionals, etc. have been handled)
  • Generally requires less code overall (jade in particular has a very terse syntax)

Cons:

  • Some performance overhead
  • Yet another thing to learn
like image 196
jmar777 Avatar answered Oct 17 '22 06:10

jmar777


About JADE or any other template language that differ a lot from HTML:

First of all it is more time consuming to debug the produced HTML. You see HTML in the browser and you need to parse it back to JADE (in your brain) to compare with your editor content. This is very inconvenient and makes debugging harder then it should be.

Of course it may not be a problem if you are the only programmer who works on the code. It may seem so easy to match the html lines with JADE lines if you are the one who wrote them.

It is a problem when working in teams.

like image 30
Marcin Malinowski Avatar answered Oct 17 '22 05:10

Marcin Malinowski