Getting started with the doT js template 2 and dotjs Template
The use of doT js {} is very similar to JSP, so it feels very friendly and comfortable to use.
{{-><%
}}->%>
For example:
<div id="evaluationtmpl"> {{ for(var prop in it) { }} <div>KEY:{{= prop }}---VALUE:{{= it[prop] }}</div> {{ } }}</div>
Is it like:
<div id="evaluationtmpl"> <% for(var prop in it) { %> <div>KEY:{{= prop }}---VALUE:{{= it[prop] }}</div> <% } %></div>
The following is an example of a dual loop:
<! Doctype html>
Running result:
Note:
1. The index of the second loop starts from 1, not from 0;
2. There are two methods to determine if of doT JS:
Statement 1:
<Body> <div id = "conditionstmpl"> {{? ! It. name }}< div> you have no name </div> {{?? }}< Div> Oh, I love your name, {{= it. name }}! </Div> {{?}} </Div>
Statement 2:
<Body> <div id = "conditionstmpl"> {if (! It. name) {}}< div> you have no name </div >{{} else {}}< div> Oh, I love your name, {= it. name }}! </Div >{{}}</div>
Refer:
Getting started with the doT js Template
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.