KeenLearner
KeenLearner

Reputation: 30

Why Pug or other templates don't follow HTML tags

I am new to Node.js. I am wondering the reason behind templates like Pug (formerly Jade) which doesn't follow the HTML syntax (having tags inside html elements). For me, it looks like this is an additional step. Can someone please help what could be the reason or am I missing something?

Upvotes: 0

Views: 1032

Answers (1)

KyleK
KyleK

Reputation: 5056

Why a template engine?

To properly isolate the view work. As it "restrict" you from inject complex code in your template, it help you keeping clean templates. It can make easier to have iterotors, mixins, variable, layout extends, etc. It make the view less technical and more independent from controller work. The aim is to just have a template that responses to a data input. Life is so easier for front-end devs that would edit templates without care about methods that are called in the backend.

Why a language structured by indent?

Why Pug/Haml/Yaml/Slim-lang or any of that language structured by indent? Because it make less code to write, it ensure you wont misstype some <a/> instead of </a>, <ab></ac>. Each additional non-needed character of code is a potential mistake. Less code to read is less code to understand if meaning-full, it's subjective but we are many to find pug more clear. Structure by indent will also force every-one to indent the template properly.

Is an additional step a bad thing?

No since in production, it's not re-compiled, so users will just render compiled templates.

Upvotes: 2

Related Questions