<% if (1 === 1) { %>
I am inside an if block!
<% } %>
<% if (0 === 1) { %>
Hello, I am in if true block!
<% } else { %>
I am actually in the else block!
<% } %>
<% const message = 'Wow I am a var named <message>'; %>
<% const rec = { w: 10, h: 2 }; %>
<% const varNames = ['w', 'h']; %>
<% const recs = [
{w: 10, h: 2},
{w: 5, h: 1},
{w: 8, h: 7},
{w: 3, h: 11}
]; %>
"<%=".
<% const message = 'Wow I am a var named <message>'; %>
Message is <%= message %>
<% const rec = { w: 10, h: 2 }; %>
<p> Width is <%= rec.w %> </p>
<p> Height is <%= rec.h %> </p>
Setting up vars 'varNames' and 'recs'
<% const varNames = ['w', 'h']; %>
<% const recs = [
{w: 10, h: 2},
{w: 5, h: 1},
{w: 8, h: 7},
{w: 3, h: 11}
]; %>
<hr>
<p>Iterating over recs (rows) and varNames (cols)</p>
<table style='border: 1px dashed green;'>
<thead style='color: blue;'>
<tr>
<% varNames.forEach(varNm => { %>
<td> <%= varNm %> </td>
<% }); %>
</tr>
</thead>
<% recs.forEach(rec => { %>
<tr>
<% varNames.forEach(varNm => { %>
<td> <%= rec[varNm] %> </td>
<% }); %>
</tr>
<% }); %>
</table>
<p> -- Switch Statement </p>
<% switch ('boo') {
case 'foo': %>
Hello I'm in the 'foo' case
<% break;
case 'boo': %>
Hello I'm in the 'boo' case
<% break;
} %>
"<%-"
<% if ('foo' === 'foo') { %>
<%- include('fields/checkbox', {}); %>
<% } %>
<p>Including file named 'choice-list.ejs' via switch</p> <% switch ('choiceList') { case 'choiceList': %> <%- include('fields/choice-list'); %> <% break; case 'checkBox': %> <%- include('fields/checkbox'); %> <% break; } %>
<p>Import (include) can pass params, here we pass params 'rec' and 'r'</p> <%- include('fields/bobby', {rec: rec, r: rec}); %>