Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

express js - ejs with layout template

Tags:

express

ejs

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?

like image 940
Chin Avatar asked Jun 08 '12 04:06

Chin


1 Answers

Actually after Express 3.X is not support layout.ejs, if you want to use the layout, following steps should be done by yourself:

  1. add dependency "express-partials": "*" in you package.json file
     "dependencies": {
       "express": "3.1.0",
       "ejs": "*",
       "express-partials": "*"
     }
  1. execute npm install to install the latest version of express-partials
  2. require express-partials in your app.js
    var partials = require('express-partials');
  3. 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.

like image 148
Liping Huang Avatar answered Sep 22 '22 13:09

Liping Huang