Hey guys i am a noob who has just started working on nodejs . I am developing a web application on nodejs using compoundjs.
This is the structure of my view folder
views/
|-- admin
| |-- games
| |-- squadplayertypes
| `-- toursection
| |-- tourformats
| |-- tourmatchtypes
| `-- tours
|-- layouts
| |-- admin
| | `-- toursection
I have created a name space to handle all requests that are directed to "/admin".
Now I want to know if there is away where I can define a common layout for all the routes inside the namespace "admin".
This is how i have written my routes.js
admin.namespace('toursection', function(toursection){
toursection.resources('tours',function(tour){
tour.post('fetchTourDetails','tours#fetchTourDetails',{collection:true});
});
toursection.resources('tourmatchtypes');
toursection.resources('tourformats');
});
/*Routes for squad players and all related dependancies*/
admin.resources('squadplayers');
Unfortunately, it doesn't look like there is currently a way to do this (at least neatly in the namespace area). Layouts are searched in the controller-extensions library, where the controller's name is used to search for a layout, then it defaults on the application layout.
However, it is possible to define one layout to be used between several views. You can use the layout
function at the top of a controller to change the layout. For example, I can define the layout app/views/layouts/reports_layout.ejs
for the reports namespace.
Example namespace:
map.namespace('reports', function (reports) {
reports.resources('billing');
});
Controller:
layout('reports');
action('index', function () {
this.title = 'Billing Report';
render();
});