Devesh Kumar
Devesh Kumar

Reputation: 1019

Accessing JADE variable in Underscore template

I am passing current user id (userid of logged in user) like

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.

I am able to access this in Jade like

p= currentUser

But I want to access this variable inside by Underscore template inside

script(type='text/template')

How can I do that?

Upvotes: 0

Views: 122

Answers (1)

Ben Fortune
Ben Fortune

Reputation: 32117

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

Upvotes: 1

Related Questions