【问题标题】:node.js : rendering error with vashnode.js:使用 vash 渲染错误
【发布时间】:2014-06-17 21:36:30
【问题描述】:

我在使用 vash 的 node.js 中出现渲染错误。我真的很难看到问题所在。以下是错误和导致错误的代码。

TypeError: Problem while rendering template at line 4, character 2.
 Original message: object is not a function. Context: 2 |
 @html.block('body', function(model){ 3 | <p>@model.title </p> > 4 |
 }); 5 | }); 6 | 7 | at helpers.extend.model
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2213:4)
 at Object.vash.loadFile
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2072:10)
 at helpers.extend
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2190:8)
 at eval (eval at <anonymous>
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:1820:24),
 <anonymous>:7:21) at vash.link.linked
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:1860:12)
 at vash.renderFile
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2082:21)
 at Object.vash.loadFile
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2070:10)
 at View.vash.renderFile [as engine]
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2078:8)
 at View.render
 (C:\Users\user009\Dropbox\cpp\node_modules\express\lib\view.js:76:8)
 at Function.app.render
 (C:\Users\user009\Dropbox\cpp\node_modules\express\lib\application.js:502:10)

路由器:

app.get("/", function (request, response) {
    response.render('index', {title: 'letsdoit'});
});

layout.vash

<!DOCTYPE html>
<html>
<head><link href="/css/site.css" rel="stylesheet" />
<title>@model.title</title></head>
<body><div> @html.block('body') </div></body></html>

index.vash

@html.extend('layout', function(model){
    @html.block('body', function(model){
        <p>@model.title </p>
    });
});

【问题讨论】:

    标签: node.js rendering viewengine vash


    【解决方案1】:

    在您的 index.vash 文件中,确保 layout.vash 文件的路径正确。

    例如,如果views文件夹结构是views/home/layout.vash和views/home/index.vash,那么:

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

    应该是:

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

    希望对你有帮助。

    【讨论】:

    • 谢谢老兄,就这样。 '家/布局'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 1970-01-01
    • 2011-11-09
    • 2013-04-16
    相关资源
    最近更新 更多