Categories
JavaScript Answers

How to pass variable from jade template file to a script file with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *