How to support the '. html ' suffix when using the Ejs template engine in EXPRESS3

Source: Internet
Author: User

①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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.