指向部分生成器网站

我使用快速生成器生成快速网站,我需要引用视图文件夹内子文件夹内的部分hbs文件。

我的文件夹结构是这样的

在这里输入图像说明

从我的主布局文件(layout.hbs)我引用head和nav_bar文件,我得到一个错误,头文件不能find

在这里输入图像说明

错误是

C:\MovementForNewNigeria\app\views\index.hbs: The partial head could not be found Error: C:\MovementForNewNigeria\app\views\index.hbs: The partial head could not be found at Object.invokePartial (C:\MovementForNewNigeria\app\node_modules\handlebars\dist\cjs\handlebars\runtime.js:266:11) at Object.invokePartialWrapper [as invokePartial] (C:\MovementForNewNigeria\app\node_modules\handlebars\dist\cjs\handlebars\runtime.js:68:39) at Object.eval (eval at createFunctionContext (C:\MovementForNewNigeria\app\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:254:23), <anonymous>:6:28) at main (C:\MovementForNewNigeria\app\node_modules\handlebars\dist\cjs\handlebars\runtime.js:173:32) at ret (C:\MovementForNewNigeria\app\node_modules\handlebars\dist\cjs\handlebars\runtime.js:176:12) at ret (C:\MovementForNewNigeria\app\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:525:21) at C:\MovementForNewNigeria\app\node_modules\hbs\lib\hbs.js:87:17 at C:\MovementForNewNigeria\app\node_modules\hbs\lib\hbs.js:69:11 at done (C:\MovementForNewNigeria\app\node_modules\hbs\lib\async.js:74:20) at C:\MovementForNewNigeria\app\node_modules\hbs\lib\hbs.js:64:20 

解决方法是注册部分或更有效地注册所有部分

 var hbs = require('hbs'); hbs.registerPartials(__dirname + '/views/partials'); 

https://github.com/pillarjs/hbs

感谢turmuka帮助importhbs。

你需要在这里使用这个代码。 它将注册您指定的path。

 app.engine('hbs', hbs({ extname: 'hbs', defaultLayout: 'base', layoutDir: __dirname + '/views/layouts', // for layouts partialsDir : [ // path to your partials __dirname + '/views/partials', ] }));