Jack Wang
Jack Wang

Reputation: 482

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?

Upvotes: 0

Views: 1136

Answers (1)

Soviut
Soviut

Reputation: 91525

First, you're trying to use a string interpolation #{user.name} outside of a string. Use !{user.name} instead for unescaped code interpolation. If you need this to be in a string you'll need to surround the variable in quotes as well.

console.log('!{user.name}');

Upvotes: 2

Related Questions