How to use multiple layout within a SailsJS app?

前端 未结 5 744
盖世英雄少女心
盖世英雄少女心 2021-02-15 13:16

My Sails.js application have separate frontend and admin layout. My view engine is ejs.

How do I use separate layouts for frontend

5条回答
  •  佛祖请我去吃肉
    2021-02-15 14:00

    Sorry for spamming your question but i need a similar solution for my app. It would be wonderful to define layouts in routes.js so for example /admin/* would use one layout, and eg. /app/* would use the other, etc. Because it's a pita do dive into controllers and overspam them with static layout paths. I tried this concept but it seems to be working only if I also define a controller in the routes.js config file eg:

    module.exports.routes = {
    
       '/admin/*' : {
          controller: 'AdminController',
          action: 'index',
          locals: {
             layout: 'admin/layout'
          }
       }
    };
    

    This does work, but is routing all actions for admin into the same controller, which is of course wrong. If I omit the controller part, that concept is always using the default view/layout.ejs and the local is not set:

    module.exports.routes = {
    
       '/admin/*' : {
          locals: {
             layout: 'admin/layout'
          }
       }
    };
    

    This doesn't work but it would be ideal to get it that way.

提交回复
热议问题