无法使用vash 0.8.0与express 4.12.3一起使用

时间:2015-03-21 22:30:18

标签: javascript node.js express vash

我正在尝试学习node.js.我希望能够使用vash视图引擎但由于某种原因我不能让它工作。我看了一篇关于Pluralsight的教程并引用了vash文档,但我一直得到同样的错误。这是我的代码

server.js:

var http = require('http');
var port = process.env.port || 1337;

var express = require("express");
var app = express();

app.set("view engine", "vash");
app.get("/", function (req, res) { 
    res.render("index", { title: "Express + Vash" });
});

var server = http.createServer(app);
server.listen(port);

layout.vash:

<!DOCTYPE html>
<html>
    <head>
        <title>@model.title</title>
    </head>
    <body>
        <div>@html.block("body")</div>
    </body>
</html>

index.vash

@html.extend('views/layout', function(model) { 

    @html.block("body", function(model) {

        <h1>@model.title</h1>
        <p>This id from the server</p>

    })

})

stacktrace:

TypeError: undefined is not a function
   at View.render (C:\Users\Michael\Desktop\Node_Stuff\LearnNode\TheBoard\node_modules\express\lib\view.js:93:8)
   at EventEmitter.app.render (C:\Users\Michael\Desktop\Node_Stuff\LearnNode\TheBoard\node_modules\express\lib\application.js:566:10)
   at ServerResponse.res.render (C:\Users\Michael\Desktop\Node_Stuff\LearnNode\TheBoard\node_modules\express\lib\response.js:938:7)
   at C:\Users\Michael\Desktop\Node_Stuff\LearnNode\TheBoard\server.js:9:9
   at Layer.handle [as handle_request] (C:\Users\Michael\Desktop\Node_Stuff\LearnNode\TheBoard\node_modules\express\lib\router\layer.js:82:5)
   at next (C:\Users\Michael\Desktop\Node_Stuff\LearnNode\TheBoard\node_modules\express\lib\router\route.js:110:13)
   at Route.dispatch (C:\Users\Michael\Desktop\Node_Stuff\LearnNode\TheBoard\node_modules\express\lib\router\route.js:91:3)
   at Layer.handle [as handle_request] (C:\Users\Michael\Desktop\Node_Stuff\LearnNode\TheBoard\node_modules\express\lib\router\layer.js:82:5)
   at C:\Users\Michael\Desktop\Node_Stuff\LearnNode\TheBoard\node_modules\express\lib\router\index.js:267:22
   at Function.proto.process_params (C:\Users\Michael\Desktop\Node_Stuff\LearnNode\TheBoard\node_modules\express\lib\router\index.js:321:12) 

.vash文件位于项目根目录的views文件夹中。

提前致谢!

2 个答案:

答案 0 :(得分:0)

this vash issue以下内容应该有效:

var vash = require('vash');
vash.__express = vash.renderFile;
app.set("view engine", "vash");

答案 1 :(得分:0)

在index.vash中,只需使用'/ layout'而不是'views / layout'。

那是:

@html.extend(**'/layout'**, function(model) { ... });