5

As far as i know, Templates are used to seperate presentation from Logic and it can be reused since it doesnot depond on any logic... Many suggested me to go for Handlebars.js for templating.(This is the first time i'm hearing this name).

I want to know What is meant by Logic-less template?

Thanks

Note: I have gone through this What's the advantage of Logic-less template (such as mustache)? question as well.. But i didnt get clear idea.

Community
  • 1
  • 1
Jeevi
  • 2,726
  • 6
  • 35
  • 58

3 Answers3

3

Handlebars is logic-less since you cannot execute JavaScript inside templates. You cannot write {{# if num==1}}. Instead, you have to prepare a boolean in JS: var numIsOne = num==1;, and the template should contain {{# if numIsOne }}. That is what logic-less means.

grebenyuksv
  • 1,549
  • 2
  • 11
  • 9
1

The basic task of a template library is to provide a mechanism to fill some computed data into the more or less static template, like to fill in the name in "Hello, ${name}". Many template libraries, however, offer additional features, like if-then statements, loops, arbitrary code execution, and so on. This is the logic that logic-less templates try to avoid.

This means that logic-less template libraries just provide the basic functionality of filling in data into a template.

The reasons for using logic-less templates are given in the question you referenced, so I won't list them here.

daniel kullmann
  • 12,359
  • 6
  • 48
  • 63
  • But in handle bar js also we have if statements rite? Then how it became logic less? – Jeevi May 21 '12 at 11:15
  • SO, It not logic less template? Then How they r compatibile with mustache js? – Jeevi May 22 '12 at 09:22
  • 2
    From the website: "Mustache templates are compatible with Handlebars, so you can take a Mustache template, import it into Handlebars, and start taking advantage of the extra Handlebars features.". This means that you can use mustache templates in handlebars.js but not necessarily use handlebar js templates in mustache, in particular if you use the additional, not-logic-less additions. – daniel kullmann May 22 '12 at 10:45
0

"Handlebars is a logic-less templating engine, which means there is little to no logic in your templates that are on the HTML page. The most important use of Handlebars, and any templating engine, is to keep your HTML pages simple and clean and decoupled from the logic-based JavaScript files, and Handlebars serves this purpose well." from javascriptissexy.com I think the quote above answers the original question!

slopeofhope
  • 604
  • 1
  • 5
  • 17