①express The default Jade template to Ejs template, you need to execute the following command:
Express-e--ejs
② in App.js, the
app.set(‘view engine‘, ‘jade‘);
Replaced by
app.engine(‘.html‘, require(‘ejs‘).__express);app.set(‘view engine‘, ‘html‘);
You can do it.
Brief description:
The first sentence is to allow Ejs to recognize files with the suffix '. html ', app.engine equivalent to App.register in Express2.
The second sentence is to automatically add the '. html ' suffix to the render function when it is called. If there is no second sentence, we have to write Res.render (' users ') as Res.render (' users.html '), otherwise it will be an error.
Reference: Render Ejs with Express
It is important to note that this method is required to add a suffix when implementing a template nesting. For example, in index.html quote header.html:
<% include header.html %>
If you omit the. html here, you will get an error.
How to support the '. html ' suffix when using the Ejs template engine in EXPRESS3