Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New to Sails.js how can I route to a view without including the layout.ejs?

New to Sails.js I've read over the docs but I don't see a way to NOT include the layout.ejs located in /views/.

I'm trying to implement Angular into my app and when I go

$routeProvider.when('/',{
  controller: 'HomeController',
  templateUrl: '/home'
})

So then in my routes I expect to be able to do:

'GET /home': { view: 'angular/home.ejs' }

But what happens is it loads home.ejs but also injects layout.ejs so it becomes an endless loop of injecting layout.ejs loading angular scripts from layout, then trying to load home.ejs which loads layout.ejs so on so forth

So how can I do this?

I know I can put views in /asset/angular/home.html but I would like to have .ejs so that I can render a different view (e.g. user is not logged in) or something.

Any information on how I can render views without injecting layout.ejs would be great, thanks!

Update:

So by doing this:

'GET /home': { 
  view: 'home',
  locals: {
    layout: false
  }
}

it makes it work, I don't know if there is a global way so I don't have to flag layout: false for each one

like image 333
Datsik Avatar asked Oct 19 '22 10:10

Datsik


1 Answers

  1. To disable layouts globally, you can put layout : false under /config/view.js.
  2. To disable layout individually, leave /config/view.js alone and do something like this in your routes:

    'GET /home': { 
        view: 'home',
        locals: {
            layout: false
        }
    }
    
like image 91
Maciej Szpakowski Avatar answered Oct 22 '22 01:10

Maciej Szpakowski