My Sails.js application have separate frontend
and admin
layout.
My view engine is ejs
.
How do I use separate layouts for frontend and admin site?
Can I use specific layout for each action?
From Sails.js Documentation:
At least in EJS, instead of indicating your custom layout with the layout local, you must use _layoutFile:
res.view({
_layoutFile: 'relativePathToYourCustomLayoutFromTheTargetView.ejs'
});
The path to the layout you're wanting to use should be specified relative to the view you're rendering. So if you're in the create action of the UserController, rendering a view (views/user/create.ejs), the relative path to your custom layout might be: ../staticSiteLayout.ejs
PROJECT FOLDER
└── views
├── staticSiteLayout.ejs
├── layout.ejs
└── user
└── create.ejs
UPDATE:
Seems like the documentation is a bit off from the code, so for the current (v0.9.8) version the way to go is the following:
module.exports = {
index: function(req, res){
res.view({ layout: 'layoutadmin' });
}
}