Change from Jade template to ejs for MEAN Stack

2019-08-11 11:34发布

问题:

I am currently new to use MEAN stack with the following packages: https://github.com/linnovate/mean. However, after I had created the project and found that Jade is their default template engine.

Are there any good ways to convert those jade template to ejs with changing related settings in Express?

Thank you.

回答1:

Inside app.js change:

app.set('view engine', 'jade');

to

app.set('view engine', 'ejs');

then

  1. Open your jade-based page on chrome browser.

  2. Open the mouse context-menu on browser and select "inspect element".

  3. Select the html tag and copy it as HTML.

  4. Paste that HTML on your favorite HTML editor or any code editor.

  5. Adjust some tags to fit to 'ejs'. For example, change 'block body' to '<%- body%> or change any data string to a data variable like {{data}} or & quot; to " ' ".

  6. save the files with ejs instead of jade.



回答2:

var express = require('express');
var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');// here you set EJS