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.