How to pass variables from a Jade.js template file to a script file with JavaScript?

Estimated read time 1 min read

To pass variables from a Jade template file to a script file, you need to use JavaScript to render the template and pass data to it as an object.

In the Jade template file, you can access the variables using the syntax #{variableName}.

In the script file, you can render the Jade template using a library such as “jade” and pass the data to it as an object, like this:

const jade = require('jade');

const data = {
  variableName: 'value'

const html = jade.renderFile('template.jade', data);

Then you can use the html variable in your script file to add the rendered HTML to the page or manipulate it in any way you need.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply