To pass variable from jade template file to a script file with JavaScript, we pass in the variable to the template with render
.
For instance, in our Jade template, we write
script.
loginName="#{login}";
Then we write
exports.index = (req, res) => {
res.render("index", { layout: false, login: req.session.login });
};
to call res.render
with an object with the login
property set to the value we want to pass to the Jade template.