1<div id="output"></div>
2<script src="ejs.min.js"></script>
3<script>
4 let people = ['geddy', 'neil', 'alex'],
5 html = ejs.render('<%= people.join(", "); %>', {people: people});
6 // With jQuery:
7 $('#output').html(html);
8 // Vanilla JS:
9 document.getElementById('output').innerHTML = html;
10</script>
1// from https://ejs.co/#about
2// EJS tags
3
4<% //'Scriptlet' tag, for control-flow, no output
5
6<%_ //‘Whitespace Slurping’ Scriptlet tag, strips all whitespace before it
7
8<%= //Outputs the value into the template (HTML escaped)
9
10<%- //Outputs the unescaped value into the template
11
12<%# //Comment tag, no execution, no output
13
14<%% //Outputs a literal '<%'
15
16%> //Plain ending tag
17
18-%> //Trim-mode ('newline slurp') tag, trims following newline
19
20_%> //‘Whitespace Slurping’ ending tag, removes all whitespace after it
21
22// use in your 'list.ejs' file which needs to be in a 'views' folder
23
24 <% if(userName === "bob" || userName === "jane"){ %>
25 <h1 style="color: purple"><%= myUserNames %></h1>
26 <% } else { %>
27 <h1 style="color: blue"><%= myUserNames %></h1>
28 <% } %>
29
30// link app.js to list.ejs and passing data
31
32 // it looks for 'list' in the 'views' folder
33 res.render("list", { myUserNames: "bob" });