Billy Tran
Billy Tran

Reputation: 43

call multi layout for controller in sails.js

SAILS.JS

I have two forder in controller: admin and public.

I want to edit view.js file in config forder.

  1. if controllers file in admin forder, it call a layout: layout-admin

  2. if controllers file in public forder, it call a layout: layout-public

    but i don't know do it.

please support for me with this. thank a lot!

Upvotes: 2

Views: 312

Answers (1)

jaumard
jaumard

Reputation: 8292

You can do what you want, look the doc here : http://sailsjs.org/documentation/reference/configuration/sails-config-views

The layout attributs can only be a string or a boolean, there no way actually to define a layout with a function or for an entire controller.

You can make a feature request to sails to see this feature in a next version.

You can specify layout file in your controller like this :

myAction : function (req, res)
{
    var layout = "layout-public";
    if(req.session.authenticated)
    {
            layout = "layout-admin";
    }
    res.view("myview", {
        layout   : layout
    });
}

Upvotes: 3

Related Questions