Luca Steeb Luca Steeb - 1 month ago 12
Node.js Question

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

I'm using the view engine vash with nodejs & express 3 and my index.vash and layout are looking as follows:

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


In app.js I set the view engine:
app.set('view engine', 'vash');

So these examples are 1:1 the same as described on github.

This question is the same, except that the solution didn't work for me. He suggests that you should give the correct path to layout.vash, but I got the two vash files (index & layout) in the same directory 'views'. I also tried
@html.extend('views/layout'..
but that didn't work either.

Every time I run the project it displays the following error for 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)

Answer

I finally solved the problem, the path was not correct in index.vash when calling extend, I just had to add a trailing slash ("/layout").