在Underscore模板中访问JADE变量

时间:2014-06-09 09:06:33

标签: javascript node.js underscore.js pug underscore.js-templating

我正在传递当前用户ID(登录用户的用户ID),如

app.get('/home', isLoggedIn, function(req, res) {
        res.render('home.jade', {
            currentUser : req.user.id 
        });
    });

现在这意味着我的home.jade文件可以访问currentUser变量。

我可以在Jade中访问这个

p= currentUser

但我想通过

中的Underscore模板访问此变量
script(type='text/template')

我该怎么做?

1 个答案:

答案 0 :(得分:1)

如果它是内联的,那么您应该能够使用#{}返回变量。

所以你想要

script(type='text/template').
    var template = _.template("<b><%- value %></b>");
    template({value: "#{currentuser}"});
相关问题