preface
Express uses the Jade template by default. There is no HTML in it. How to implement this template?
Ejs template configuration
use
var app = express();
app.set('views', path.join(__dirname, 'views')); // Set the view engine app.set('view engine'.'ejs');
Copy the code
HTML Template Configuration
Install the ejs
npm install ejs -D
Copy the code
The introduction of
var ejs = require('ejs');
Copy the code
use
var app = express();
var ejs = require('ejs');
app.set('views', path.join(__dirname, 'views'));
app.engine('html', ejs.__express);
app.set('view engine'.'html');
Copy the code
instructions
app.engine(ext, cb)
app.engine('html', require('ejs').__express);
Copy the code
Map the EJS template to an.html file;
This is actually a call to ejS’s.renderFile() method, which ejs.__express is another name for inside EJS.
Since the same.__express method is invoked after the template engine is loaded, you do not need to configure this item if you are using ejS templates.
app.set(name, value)
One of the arguments to the.set() method is’ View engine’, which is the default engine plug-in to use when no template format is specified;
If this is set to an HTML file, when you set the route to the specified file, you just write the file name and it will find the corresponding HTML file.