4. Mustache
●Template engine / render engine
●Lack of any logic statement like if … else
●Compatible with popular Javascript Framework
● Client side - Jquery, YUI, Dojo
● Server side – Node.js
4
6. Why use?
Before I tell you why we use templates engine
compare this example ...
6
7. Data model
{
"name" : "korkeat",
"username" : "khasathan",
"url" : "http://khasathan.in.th"
"programming" :
["Java","PHP","Python"]
}
7
8. … And we expect result as ...
<h1>Profile of korkeat</h1>
<p>Username: khasathan</p>
<p>Url: http://khasathan.in.th</p>
<ul>
<li>Java</li>
<li>PHP</li>
<li>Python</li>
</ul>
8
9. Without template engine
var html = '';
html += '<h1>Profile of ' + DATA_MODEL.name + '</h1>';
html += '<p>Username: '+ DATA_MODEL.username +'</p>';
html += '<p>Url: '+ DATA_MODEL.url +'</p>';
html += '<ul>';
for(lang in DATA_MODEL.programming) {
html += '<li>'+ lang +'</li>';
}
html += '</ul>';
console.log(html);
9