Thursday, 25 May 2017

Nodejs: Is there a better way to create html templates other than putting it in a string?

I have a nodejs code where I pass an preformatted html to sparkpost to send an email. Right now, I have the template in a variable and just pass it to sparkpost api like so:

var htmlBody = '<html><body> Hello ' + user + '! Welcome home!</body></html>';

sendToSparkPost(htmlBody);

Is there a better way of doing this? I imagine it will become messy when I actually add more content in the html. I was thinking, I want to put the html in another file and just call it via require(something)? Is that even possible? Maybe something like this?

var htmlBody = getTemplate('something.html');

sendToRequest(htmlBody);

How do I achieve that effect?



via beef

No comments:

Post a Comment