如何使用车把更改快递中的默认布局? [英] How to change default layout in express using handlebars?

查看:20
本文介绍了如何使用车把更改快递中的默认布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Express 4.9.0 和 express-generator.

I am using Express 4.9.0 and express-generator.

使用以下命令创建样板:

Created boilerplate with a following command:

express --hbs projectname

内置把手默认使用 views/layout.hbs 作为母版页.但是我在 app.js 中看不到任何设置来改变这种行为.

Builtin handlebars is using views/layout.hbs by default as a master page. But i cannot see any settings in my app.js to change that behaviour.

来自我的 app.js 的一段代码:

piece of code from my app.js:

//查看引擎设置app.set('views', path.join(__dirname, 'views'));app.set('视图引擎', 'hbs');

  1. 如何全局更改默认布局?
  2. 如果我想要 2 或 3 个不同的全局布局怎么办?

推荐答案

您可以指定要用作渲染调用的一部分的布局.如果您创建一个名为 other.hbs 的新布局,则可以执行以下操作:

You can specify what layout you want to use as part of the render call. If you create a new layout called other.hbs, you can then do something like:

res.render('view', { title: 'my other page', layout: 'other' });

要为整个应用程序覆盖它,您可以使用:

To override this for the entire application, you can use:

app.set('view options', { layout: 'other' });

这篇关于如何使用车把更改快递中的默认布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆