Jade vs EJS, pros and cons of each and what are each designed for?

Are there any other fast compatible template engines as well and why?

Watching: What is Ejs

I have used Jade before. The nice thing about Jade is that you have shorter syntax which means you can type faster. Blocks in Jade are quite powerful which can help me a lot when dealing with complex HTML code.

On the other hand, it’s hard to do some simple stuff in Jade, which is like adding classes to a DIV based on a simple if condition. I need to put something like this

– if (isAdmin) div.admin.user- else div.userJade also doesn’t distinguish between tags and variables making the code very confusing (for me at least)

a(href=”/user/” + user.id)= user.nameJade is also not designer friendly. My design friends often give me HTML and CSS (They switched to LESS recently but still want to use HTML) and for that reason if I use Jade I need to convert the HTML to Jade. Also in Jade we need to use indentations, so if your HTML structure gets complicated your code will look horrible (especially tables). Sometimes, I don’t even know what level I’m on

table thead tr td an img tr td tbody tr td Recently I switched to EJS and I am happy with it so far. It’s very close to pure HTML and uses the same syntax as that of the frontend template engine I’m using (underscore pattern).

See also: What is Slash – Meaning of Slash in Vietnamese

See also: What is Rescue – Meaning of the word Rescue

READ MORE  About Humanity

I must say that everything is easier with EJS. I don’t have to do all the conversions when I get HTML templates from my designer friend. All I had to do was replace the dynamic parts with variables passed from ExpressJS. Things that drive me crazy using Jade are solved in EJS

div class=”user”>div>And what can I know with EJS

a href=”/user/”> user.name %>a>If you miss Jade’s short syntax (like me), you can combine Zen-Coding and EJS which can speed you up in general . In terms of performance, I don’t see any difference

However, EJS is not as powerful as Jade, it doesn’t have blocks by default (this guy has implemented blocking for EJS https://github.com/RandomEtc/ejs-locals)

So it’s completely up to you to choose whatever makes you comfortable. But if you are going to use a different template engine for frontend like me, it would be better if you use the same thing for both sides

Update Dec 16, 2013: I recently switched from EJS to Swig (which is similar in concept to Jinja2 in Python world). The main reason is the lack of blocks in EJS even with the help of ejs-locals. Swig is also using plain HTML for templates and lots of cool features template engine should have eg filters and tags that EJS doesn’t have