Le Qs
Le Qs

Reputation: 805

Setting layout and title in sails

I want to fetch a view and its specific layout in controller and once that is done,i want to use variables inside the controller in the view and layout.

I want to use title in the layout and other variables in the view.

Currently i have this and i cant change the title in my layout

hi: function (req, res) {
      res.view('noder/home',{ layout: 'layout' },{
   locals: {
      title : 'hello'
   }
})},

How can i change the title in the layout on controller basis and use other variables within my view?

Upvotes: 1

Views: 255

Answers (1)

MjZac
MjZac

Reputation: 3526

Try this:

hi: function(req, res) {
        res.view('noder/home', {
            layout: 'layout',
            title: 'hello'
        });
    }

Make sure your layout.ejs file has following line in title tag

<title><%- title %></title>

Upvotes: 1

Related Questions