Node. js + express multiple layout file applications

Source: Internet
Author: User

These days, I have contacted node. js + express and found that no matter whether jade or ejs template system is used, a layout. (Jade | ejs) file will be automatically created. It is also used in a file name convention, instead of specifying layout in the code. However, in actual projects, multiple layout files may be required to render the page layout. It is impossible for the creator of the template system to skip this consideration. So how should we implement it?

In fact, it is very simple, but I have not read the documents from the system.

When you render a page, if you do not specify layout, the system will automatically search for the layout. (Jade | ejs) file in the view folder. You can also use the specified layout file to render the page:

App. Get ('/', function (req, Res ){
Res. Render ('index ',{
Title: 'express'
, Layout: 'layout2'
});
});

In this way, render () uses layout2. (Jade | ejs) to build the page.

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.