开发者

In Express/EJS, how do I change the default layout?

I don't want it to be layout.ejs.

I want to se开发者_运维百科t my layout to be another template for THIS specific controller.


Try using:

app.set("view options", { layout: "mylayout.jade" });


Use the layout option to res.render()

res.render('page', { layout: 'mylayout.jade' })


Set custom default layout

Just set layout property in express app settings.

app.set('layout', 'layouts/layout');

Set custom layout for single render

Just pass layout as render locals object.

app.get('/', function(req, res) {
  res.render('the-view', { layout: 'specific-layout' });
);

More info here: https://www.npmjs.com/package/express-ejs-layouts


Providing you're using the Ejs-express-layouts module you can specify a layout for a particular view, overriding the default:

app.get('/', function(req, res){
  res.render('aView', { layout: 'someSpecificLayout' })
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜