javascript - Node js + template replace content -


i working generate offer letter employees. have default template index.html:

index.html

<!doctype html> <html> <head> </head> <body>  <div id="header"> <h1>offer letter</h1> </div>  <div id="name">  hello [[name]],  welcome our organization,'  details:  [[date]]    : offer letter date [[name]]    : employee name [[designation]] : designation [[address]] : communication address [[ctc]]  : cost company  </div>  <div id="footer"> copyright </div>  </body> </html> 

i generate multiple offers @ time more 300.

so have json data this:

var obj = [  { "name" : "abc",   "date" : "12-12-2014",   "designation" : "admin",   "address" : "xxxx",   "ctc" : 3333}, { "name" : "wefrwe",   "date" : "12-12-2014",   "designation" : "admin",   "address" : "xxxx",   "ctc" : 55}, { "name" : "dssd",   "date" : "12-12-2015",   "designation" : "admin",   "address" : "xxxx",   "ctc" : 333}, { "name" : "gfsc",   "date" : "12-1-2014",   "designation" : "admin",   "address" : "xxxx",   "ctc" : 22}, { "name" : "dssdds",   "date" : "1-12-2014",   "designation" : "admin",   "address" : "xxxx",   "ctc" : 4334} ]; 

how replace values (eg. [[name]] abc ) .

have node packages ?

i tried following code don't know best way , useful.

for(i in obj) {   var textbody = '<!doctype html> <html> <head> </head> <body> <div id="header"> <h1>offer letter</h1> </div> <div id="name"> hello [[name]], welcome our organization,' details: [[date]] : offer letter date [[name]]    : employee name [[designation]] : designation [[address]]   : communication address [[ctc]]  : cost company </div> <div id="footer"> copyright </div> </body> </html>';   textbody = textbody.replace(/{[^{{}}]+}/g, function(key){     return obj[key.replace(/[{{}}]+/g, "")] || ""; });  } 

refer sending email using node, nodemailer & jade

how send html page email in nodejs

your jade template should similar(or better than) to:

doctype html html     head     body         p             | hello #{newemp.name},             br             br             | welcome our organization.             br             br             | details:             br             | #{newemp.date}  : offer letter date             br             | #{newemp.name}  : employee name             br             | #{newemp.designation}  : designation             br             | #{newemp.address}  : communication address             br             | #{newemp.ctc}  : cost company 

and

in referred link, need pass context below:

var context = {                   "name" : "abc",                  "date" : "12-12-2014",                  "designation" : "admin",                  "address" : "xxxx",                  "ctc" : 3333               }; 

i did harcode context variable 1 employee object simplicity, need dynamically pass each employee object each email.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -