express js - ejs with layout template
ejs, express
Solution
Actually after Express 3.X is not support layout.ejs, if you want to use the layout, following steps should be done by yourself:
- add dependency "express-partials": "*" in you `package.json` file
"dependencies": {
"express": "3.1.0",
"ejs": "*",
"express-partials": "*"
}
- execute `npm install` to install the latest version of `express-partials`
- require `express-partials` in your `app.js` `var partials = require('express-partials');`
- add code `app.use(partials());` under the `app.set('view engine', 'ejs');` in `app.js` file
after that, you can design you `layout.ejs` and add `<%- body%>` block in your `layout.ejs` file, and that's enough and working well.
Problem
In my express app, I've changed the view engine to ejs. Does anyone know if it is still possible to take advantage of view templates?