Answer the question
In order to leave comments, you need to log in
How to pass a variable to the Jade template engine from the server side (Express.js, Node.js)?
Hello.
Server side:
io.sockets.on('connection', function(socket) {
room.getTitle(req.param('id'), function(err, result) {
if(result.length > 0) {
var title = result[0].title;
socket.join(title);
res.render('room', { title: 'Title ' + title });
}
});
});
Answer the question
In order to leave comments, you need to log in
Stop. Every time you load a page, you add a callback to connection socket.io, are you serious? :) The page will be rendered after res.render is called, res.render will be called after socket.io is connected, and why connect if the client connects, if I understand correctly, on a page that you haven't rendered yet? :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question