Node.js – EJS – including a partial

With Express 3.0: <%- include myview.ejs %> the path is relative from the caller who includes the file, not from the views directory set with app.set(“views”, “path/to/views”). EJS v1 includes EJS v2 includes (Update: the newest syntax for ejs v3.0.1 is <%- include(‘myview.ejs’) %>)

Error: Cannot find module ‘ejs’

I had this exact same problem a couple of days ago and couldn’t figure it out. Haven’t managed to fix the problem properly but this works as a temporary fix: Go up one level (above app.js) and do npm install ejs. It will create a new node_modules folder and Express should find the module then.

Can I use conditional statements with EJS templates (in JMVC)?

Conditionals work if they’re structured correctly, I ran into this issue and figured it out. For conditionals, the tag before else has to be paired with the end tag of the previous if otherwise the statements will evaluate separately and produce an error. ERROR! <% if(true){ %> <h1>foo</h1> <% } %> <% else{ %> <h1>bar</h1> … Read more