Vash 视图引擎在使用 nodejs 和 express 3 渲染时总是出错

Vash view engine gives always an error when rendering using nodejs & express 3

我将视图引擎 vash 与 nodejs & express 3 一起使用,我的 index.vash 和布局如下所示:

// index.vash
@html.extend('layout', function(model){
    @html.block('body', function(model){
        <span class="name">Welcome</span>
    })
})

// layout.vash
<p>
    @html.block('body')
</p>

app.js:

app.get('/', function (req, res) {
    res.render('index');
});

在app.js中我设置了视图引擎:app.set('view engine', 'vash'); 因此,这些示例 1:1 与 github 中描述的相同。

This 问题是一样的,只是解决方案对我不起作用。他建议你应该给出 layout.vash 的正确路径,但我在同一目录 'views' 中得到了两个 vash 文件(索引和布局)。我也试过 @html.extend('views/layout'..,但也没用。

每次我运行项目时,它都会显示 index.vash 的以下错误:

Express
500 TypeError: Problem while rendering template at line 5, character 1.
Original message: object is not a function.
Context:

3 | @html.block('body', function(model){
4 | Welcome
-> 5 | })
6 | })

at C:\Users\Luca\Documents\VSProjects\Website\TestApp\TestApp\node_modules\vash\build\vash.js:2213:4 at Object.vash.loadFile (C:\Users\Luca\Documents\VSProjects\Website\TestApp\TestApp\node_modules\vash\build\vash.js:2072:10) at helpers.extend (C:\Users\Luca\Documents\VSProjects\Website\TestApp\TestApp\node_modules\vash\build\vash.js:2190:8) at eval (eval at (C:\Users\Luca\Documents\VSProjects\Website\TestApp\TestApp\node_modules\vash\build\vash.js:1820:24), :17:21) at linked (C:\Users\Luca\Documents\VSProjects\Website\TestApp\TestApp\node_modules\vash\build\vash.js:1860:12) at C:\Users\Luca\Documents\VSProjects\Website\TestApp\TestApp\node_modules\vash\build\vash.js:2082:21 at Object.vash.loadFile (C:\Users\Luca\Documents\VSProjects\Website\TestApp\TestApp\node_modules\vash\build\vash.js:2070:10) at View.vash.renderFile [as engine] (C:\Users\Luca\Documents\VSProjects\Website\TestApp\TestApp\node_modules\vash\build\vash.js:2078:8) at View.render (C:\Users\Luca\Documents\VSProjects\Website\TestApp\TestApp\node_modules\express\lib\view.js:76:8) at Function.app.render (C:\Users\Luca\Documents\VSProjects\Website\TestApp\TestApp\node_modules\express\lib\application.js:504:10)

终于解决了问题,调用extend时index.vash中的路径不正确,只需要添加一个尾部斜杠(“/layout”)即可。

就我而言,我正在将一个项目从 MVC 迁移到 Node/Vash。
并且Vash布局文件中有一些注释掉的MVC代码,导致渲染出现问题