Jack Wang Jack Wang - 2 months ago 41
Jade Question

how to render JavaScript using pug/jade

For example, I pass a

user
variable to this pug file, and I want to run some js code after dom has loaded.

script.
document.addEventListener("DOMContentLoaded", function(event) {
console.log(#{user.name});//log the user's name
});


Is it possible to do so?

Answer

First, you're trying to use a string interpolation #{user.name} outside of a string. Use !{user.name} instead for unescaped code interpolation.

Comments