Class 11 Reading EJS - Ginsusamurai/seattle-301d58 GitHub Wiki

EJS

  • libs express, cors, body-parser, ejs
  • path module is core to node *let's you concat the CWD with views
  • app.set('view engine', 'ejs'); create view engine
  • views folder has <% index.ejs which is auto-created
    • this can find the file automatically
  • response.render('filename', {foo: 'bar'});
    • let's you pass object vals directly in to a file
    • <%= foo %> is the ejs template tag (like {{}} in angular or handlebars)
  • can also take an array of objects people: [ {name: 'dave'}]
    • <% for(var person of people){ %>
       <% if (person.name === 'dave') { %>
         <li>This is <%= person.name %></li>
       <% } else { %>
         <li> this is not dave, it's <%= person.name %></li>
       <% } %>
       <% } %>
      <% } %> 
      
⚠️ **GitHub.com Fallback** ⚠️