Multiple View paths on Node.js + Express

前端 未结 5 1616
一向
一向 2020-12-02 15:25

I\'m writing a CMS on Node.js with Express Framework. On my CMS I have several modules for users, pages, etc.

I want that each module will have his

5条回答
  •  时光说笑
    2020-12-02 16:01

    You can however, put all the view files inside the 'view' folder, but separate each module's view into it's own folders inside the 'view' folder. So, the structure is something like this :

    views  
    --moduleA    
    --moduleB  
    ----submoduleB1  
    ----submoduleB2  
    --moduleC  
    

    Set the view files like usual :

    app.set('views', './views');
    

    And when render for each module, include the module's name :

    res.render('moduleA/index', ...);
    

    or even submodule's name :

    res.render('moduleB/submoduleB1/index', ...);
    

    This solution is also works in express before version 4.x,

提交回复
热议问题