简体   繁体   English

在Underscore模板中访问JADE变量

[英]Accessing JADE variable in Underscore template

I am passing current user id (userid of logged in user) like 我正在传递当前用户ID(已登录用户的用户ID),例如

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

Now this means my home.jade file has access to currentUser variable. 现在这意味着我的home.jade文件可以访问currentUser变量。

I am able to access this in Jade like 我可以像在玉一样访问

p= currentUser

But I want to access this variable inside by Underscore template inside 但是我想通过Underscore模板访问内部的此变量

script(type='text/template')

How can I do that? 我怎样才能做到这一点?

If it's inline then you should be able to return your variable using #{} . 如果是内联的,那么您应该可以使用#{}返回变量。

So you'd want 所以你想要

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM