kirbysayshi/vash

Access filename within a vash html file

Closed this issue · 2 comments

I want to access the filename within a vash html file.
For example:
app.js:

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

blog.vash:

<p>
     @html.fileName
</p>

I want to use it to know on what page the user is and hightlight it in a navigation bar.
Is it possible?

No, this is not currently exposed in the template's executing environment. But one way to do it is to just pass in the value when rendering:

app.get('/blog', function (req, res) {
    res.render('blog', { navItem: 'blog' });
});

OK, then I'll write a function which will add a navItem to the model object
while rendering a file. The function will be added in app.use.

app.use(function (req, res, next) {
    res.renderView = function (view, object)  {
        object = object || {};
        object.navItem = view;
        res.render(view, object);
    }
    next();
}

Andrew Petersen notifications@github.com schrieb am Mi., 22. Juli 2015
07:35:

Closed #86 #86.


Reply to this email directly or view it on GitHub
#86 (comment).