![](/img/trans.png)
[英]How to set up a default layout in nest.js using Handlebars.js?
[英]How to set handlebars layout directory?
這是我的nodejs express
使用把手為視圖和目錄進行的nodejs express
設置:
- server.js
- routes
|-- index.js
-config
|-- config.js
- client
|-- public
| | -- js
| | -- css
| | -- font
|-- views
|-- index.html
|-- layout
|-- layout.handlebars
| ... other directories
這是我的node.js代碼:
// Set static folder
app.use(express.static(path.join(__dirname, '/client/public')));
// Views and view engine
app.set('views', path.join(__dirname, '/client/views'));
app.set('view engine', 'ejs');
app.engine('html', handlebars({ defaultLayout: 'layout' }));
車把無法找到我的布局。 它正在查看app/views/layouts/layout.handlebars
,但應該在app/client/views/layouts/layout.handlebars
我在這里想念什么?
好像您正在使用快速車把
創建實例時,需要指向目錄。
const hbs = exphbs.create({
extname :'hbs',
layoutsDir : 'path/to/layout/directory',
defaultLayout: 'main',
helpers : 'path/to/helpers/directory',
partialsDir : [
'path/to/partials/directory'
]
});
如果不使用自定義文件夾位置來啟動它,它將在默認位置中查找文件。
另外,視圖引擎需要設置為hbs.engine
而不是ejs
app.engine('hbs', hbs.engine);
app.set('view engine', 'hbs');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.