Closed dreammonkey closed 11 years ago
ref to https://github.com/balderdashy/sails/wiki/views
If you need to override a layout for a specific view, you can do so in the res.view call as below:
res.view({
layout: "different_layout"
})
Re: your other question, you can use config/local.js to set global settings that will then be accessible through sails.config
. For code that you want to re-use across multiple controllers, you can use services, or if you want certain pieces of code to run before certain routes, you can use policies.
I'm trying to use different template files for specific controllers, but they are not showing up and only the view is returned, I've tried placing the files in the root of the /views folder and in a separate /views/templates folder. none of which seem to work.
My code: /config/views.js: layout : 'templates/default'
/api/controllers/AdminController.js: index : function(req, res){ res.locals.layout = '/templates/admin'; res.view({ bodyclasses: 'admin nl login'}); }
Not sure what's going wrong.
An additional question: I love the way Sails is structured. I come from a php background and I've worked a lot with CodeIgniter. I was kind of hoping to find a similar workflow with Sails but there are a few things I don't fully understand yet.
In CI you could overwrite the default Controller, (i.e. My_Controller). This would allow you to write code that can be accessed form all your controllers and would also allow you to make global settings (depending on requests) that should no longer be configured in all of the separate controllers (DRY).
I know there must me a way to accomplish this in Sails, I guess I'm just not seeing it.
For instance something we use a lot in Belgium (because we have a French and Dutch speaking community) is setting a language string in the body class. This is typically something that would be handled higher up the framework, you shouldn't want to write that piece of code every time you create a new controller method...
Sorry for my long post, I'm open to suggestions, tutorials, etc...
D