如何改变车把延伸为快递? [英] How to change handlebars extension for express?
问题描述
我是node.js的新手,我想使用句柄模板引擎,但缩写扩展 hbs
。
以下是原始代码(源):
var handlebars = require('express3-handlebars')
.create({defaultLayout:'main'});
app.engine('handlebars',handlebars.engine);
app.set('view engine','handlebars');
使用 handlebars
扩展名的模板,但我将它改为:
var handlebars = require('express3-handlebars')
.create({ defaultLayout:'main'});
app.engine('hbs',handlebars.engine);
app.set('view engine','hbs');
然后将所有模板扩展更改为 hbs
。
然而,现在我得到这个错误:
错误:ENOENT:没有这样的文件或目录,打开'/ path /to/node/myproject/views/layouts/main.handlebars'
at Error(native)
我也试过
pre code $ var handlebars = require('express3-handlebars')
.create({defaultLayout :'main',extname:'.hbs'});
app.engine('handlebars',handlebars.engine);
app.set('view engine','handlebars');
根据答案 here ,
但我得到的结果是:
错误:未能在视图目录/ path / to / myproject / views中查找视图500$ EventEmitter.render处的
(/path/to/myproject/node_modules/express/lib/application.js: 579:17)ServerResponse.render处的
(/path/to/myproject/node_modules/express/lib/response.js:961:7)在/path/to/myproject/app.js处
: 96:6
在Layer.handle_error(/path/to/myproject/node_modules/express/lib/router/layer.js:71:5)
在trim_prefix(/ path / to / myproject / node_modules /express/lib/router/index.js:310:13)
at /path/to/myproject/node_modules/express/lib/router/index.js:280:7
at Function.process_params (/path/to/myproject/node_modules/express/lib/router/index.js:330:12)在下一个
(/path/to/myproject/node_modules/express/lib/router/index.js: 271:10)
在Layer.handle_error(/ path / to / myproject /node_modules/express/lib/router/layer.js:67:12)
at trim_prefix(/path/to/myproject/node_modules/express/lib/router/index.js:310:13)
我也试过其他东西,但都没有工作,所以想知道我该如何解决这个问题?
exphbs = require() 'express3-handlebars'),
app.engine('hbs',exphbs({defaultLayout:'main',extname:'.hbs'}));
app.set('view engine','hbs');
I am new to node.js and I'd like to use handlebars template engine but with a shorten extension hbs
.
Here is the original code (source):
var handlebars = require('express3-handlebars')
.create({ defaultLayout: 'main' });
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
It worked fine with templates with handlebars
extension, but I changed it to:
var handlebars = require('express3-handlebars')
.create({ defaultLayout: 'main' });
app.engine('hbs', handlebars.engine);
app.set('view engine', 'hbs');
And change all the template extentions to hbs
.
However, now I get this error:
Error: ENOENT: no such file or directory, open '/path/to/node/myproject/views/layouts/main.handlebars'
at Error (native)
I also tried
var handlebars = require('express3-handlebars')
.create({ defaultLayout: 'main' , extname : '.hbs'});
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
as per answer here,
but I results in:
Error: Failed to lookup view "500" in views directory "/path/to/myproject/views"
at EventEmitter.render (/path/to/myproject/node_modules/express/lib/application.js:579:17)
at ServerResponse.render (/path/to/myproject/node_modules/express/lib/response.js:961:7)
at /path/to/myproject/app.js:96:6
at Layer.handle_error (/path/to/myproject/node_modules/express/lib/router/layer.js:71:5)
at trim_prefix (/path/to/myproject/node_modules/express/lib/router/index.js:310:13)
at /path/to/myproject/node_modules/express/lib/router/index.js:280:7
at Function.process_params (/path/to/myproject/node_modules/express/lib/router/index.js:330:12)
at next (/path/to/myproject/node_modules/express/lib/router/index.js:271:10)
at Layer.handle_error (/path/to/myproject/node_modules/express/lib/router/layer.js:67:12)
at trim_prefix (/path/to/myproject/node_modules/express/lib/router/index.js:310:13)
I tried other things too but none worked so wondering how can I fix this?
This did the trick:
exphbs = require('express3-handlebars'),
app.engine('hbs', exphbs({defaultLayout: 'main', extname: '.hbs'}));
app.set('view engine', 'hbs');
这篇关于如何改变车把延伸为快递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!