Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

New line in node.js mailer template

New line in node.js mailer template

Problem

I'm using node.js mailer module to send email from node server. I used template file for that but I got all spaces trimmed when the message was sent. I tried to add '\n' at the end line of the template but it doesn't work also. Here is an example of template file:

Hi {{username}},\\n

Thanks for creating an account with us

I tried \n and \n , nothing all doesn't work. Any help?

Thanks,

Problem courtesy of: Feras Odeh

Solution

It's a known behavior, mustache is made to work with HTML templates, in HTML, new lines will be contracted as one space only.

You can try doing something like {{new_line}} instead your \\n, and define new_line: "\n\xA0" in your datas. \xA0 is the non-breakable space, it can separate line if you want to make two new lines.

An other solution is to not use the template, but just get the content of the file as text with fs.readFileSync(filename) and use a regexp to replace {{xxx}} by an object content.

Solution courtesy of: Tronix117

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

New line in node.js mailer template

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×