Nomura Nori
Nomura Nori

Reputation: 5167

how to set server variable to javascript src attribute in pug template using node.js?

I am integrating api with Node.js and I have to set src attribute of script as server variable. Here is real code.(what i want to execute)

Server side
res.render('sample', {usertoken:'somerandomstring'});

Client side
script(src='https://apibaseurl/'+#{usertoken}+'/en.min.js')

The result I want is

script(src='https://apibaseurl/somerandomstring/en.min.js')

How to do it and what am i wrong?

Upvotes: 0

Views: 362

Answers (2)

Nomura Nori
Nomura Nori

Reputation: 5167

script(src='https://apibaseurl/'+usertoken+'/en.min.js')

Upvotes: 0

ayxos
ayxos

Reputation: 408

Define it first:

(Client side)

script.
  var usertoken ="#{usertoken}";
  var script = document.createElement('script');
  script.src = "https://apibaseurl/" + usertoken + "/en.min.js";
  document.body.appendChild(script);

Upvotes: 1

Related Questions