我使用带有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上描述的相同。
这的问题是一样的,只是这个解决方案对我不起作用。他建议您应该给出正确的layout.vash路径,但是我在同一个目录“视图”中得到了两个vash文件(索引和布局)。我也尝试过@html.extend('views/layout'..,但这也不起作用。
每次运行该项目时,它都会显示index.vash的以下错误:
快递 500 TypeError:呈现第5行字符1的模板时出现的问题。 原始消息:对象不是函数。 上下文: 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)
发布于 2015-01-09 16:40:09
我终于解决了这个问题,在index.vash中调用扩展时路径是不正确的,我只需要添加一个尾随斜杠("/layout")。
发布于 2016-11-10 15:19:29
在我的例子中,我将一个项目从MVC迁移到Node/Vash。
并且Vash布局文件中有一些注释的MVC代码,这就导致了渲染问题。
https://stackoverflow.com/questions/27741874
复制相似问题