Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Logic-less template

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.

like image 289
Jeevi Avatar asked Oct 09 '22 23:10

Jeevi


2 Answers

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.

like image 107
grebenyuksv Avatar answered Oct 14 '22 04:10

grebenyuksv


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.

like image 21
daniel kullmann Avatar answered Oct 14 '22 05:10

daniel kullmann