-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathejs-parser.js
More file actions
59 lines (52 loc) · 1.57 KB
/
Copy pathejs-parser.js
File metadata and controls
59 lines (52 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
console.log("HTML Template Parsing using EJS");
console.log("-------------------------------");
let ejs = require('ejs');
let data = {
"firstname": "Rakesh",
"Evaluations": [
{ "link": "https://test1.com/john", "round": "Screening", "candidate": "John" },
{ "link": "https://test1.com/bob", "round": "Essay", "candidate": "Bob" },
]
};
console.log('Handling using for statement. Content Follows:');
console.log('----------------------------------------------');
let templateFor = `Dear <%= data.firstname %>,
<table>
<tr>
<td>Candidate</td>
<td>Round</td>
</tr>
<% for(var i = 0; i < data.Evaluations.length; i++) { %>
<tr>
<td>
<a src="<%= data.Evaluations[i].link %>"><%= data.Evaluations[i].candidate %></a>
</td>
<td>
<%= data.Evaluations[i].round %>
</td>
</tr>
<% } %>
</table>`;
console.log(ejs.render(templateFor, { data: data }));
console.log('--------------------------------------------------');
console.log('Handling using foreach statement. Content Follows:');
console.log('--------------------------------------------------');
let templateForEach = `
Dear <%= data.firstname %>,
<table>
<tr>
<td>Candidate</td>
<td>Round</td>
</tr>
<% data.Evaluations.forEach(function(item) { %>
<tr>
<td>
<a src="<%= item.link %>"><%= item.candidate %></a>
</td>
<td>
<%= item.round %>
</td>
</tr>
<% }); %>
</table>`;
console.log(ejs.render(templateForEach, { data: data }));