Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在NodeJs中更改把手延长件_Node.js_Templates_Express_Handlebars.js - Fatal编程技术网

Node.js 在NodeJs中更改把手延长件

Node.js 在NodeJs中更改把手延长件,node.js,templates,express,handlebars.js,Node.js,Templates,Express,Handlebars.js,嗨, 我的模板文件的扩展名为.handlebar,我想将其更改为.hbs const express = require('express'); const exphbs = require('express-handlebars'); const app = express(); app.engine('handlebars', exphbs({defaultLayout: 'index'})); app.set('view engine', 'handlebars'); 将handl

嗨, 我的模板文件的扩展名为
.handlebar
,我想将其更改为
.hbs

const express = require('express');
const exphbs  = require('express-handlebars');

const app = express();

app.engine('handlebars', exphbs({defaultLayout: 'index'}));
app.set('view engine', 'handlebars');
handlebar
更改为
hbs
并重命名文件时,会出现错误。这些文件再也找不到了


缺少什么?

请尝试设置以下属性

const exphbs  = require('express-handlebars');
const handlebars = exphbs.create({
  // layoutsDir: path.join(__dirname, 'app/views/layouts'),
  // partialsDir: path.join(__dirname, 'app/views/partials'),
  defaultLayout: 'index',
  extname: 'hbs'
});

app.engine('hbs', handlebars.engine);
app.set('view engine', '.hbs');

尝试设置以下属性

const exphbs  = require('express-handlebars');
const handlebars = exphbs.create({
  // layoutsDir: path.join(__dirname, 'app/views/layouts'),
  // partialsDir: path.join(__dirname, 'app/views/partials'),
  defaultLayout: 'index',
  extname: 'hbs'
});

app.engine('hbs', handlebars.engine);
app.set('view engine', '.hbs');

更改代码,如下所示:

`

从更改文件的扩展名
.hanlebar

.hbs
并将您的
索引.hbs
文件放在
路径/到/项目/视图/布局中,其余的
。hbs
文件应保留在
路径/到/项目/视图中/

更改代码如下:

`

从更改文件的扩展名
.hanlebar

.hbs
并将您的
索引.hbs
文件放在
路径/到/项目/视图/布局中
的其余部分中。hbs
文件应保留在
路径/到/项目/视图中
,这真的很烦人,主文件
索引
应该放在其他模板文件的上方,而不是下方。这确实令人讨厌,主文件
索引
应该放在其他模板文件的上方,而不是下方