node.js : rendering error with vash

微笑、不失礼 提交于 2019-12-23 16:21:17

问题


I'm getting a rendering error in node.js with vash. I'm really struggling to see what the issue is. Below is the error and the code causing the error.

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)

router:

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>
    });
});

回答1:


In your index.vash file, make sure the path to the layout.vash file is correct.

For example, if the views folder structure is views/home/layout.vash and views/home/index.vash, then:

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

should be:

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

hope it helps.



来源:https://stackoverflow.com/questions/23407173/node-js-rendering-error-with-vash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!