First a correction to my original code: It is $orderNote.Comment.replace(...), not $orderNote.replace(...).
As I metioned in my original post, I tried "\r\n", "\\r\\n", "\\\r\\\n", and "\\\\r\\\\n", and none of them work.
I did a little more searching this morning, and found a suggestion to put "\r" and "\n" into the context, so I added two lines to the Process method in CommerceBuilder/Messaging/NVelocityEngine.cs:
Code: Select all
public string Process(Hashtable parameters, string template)
{
string retVal = string.Empty;
using (StringWriter writer = new StringWriter())
{
using (StringReader templateReader = new StringReader(template))
{
VelocityContext context = new VelocityContext(parameters);
context.Put("helper", new NVelocityHelper());
// following two lines allow .replace("${r}${n}", "<br />") on strings in email templates
context.Put("n", "\n");
context.Put("r", "\r");
this.Evaluate(context, writer, "AbleCommerce", templateReader);
}
retVal = writer.ToString();
}
return retVal;
}
Then you use it in replace like this:
Code: Select all
$orderNote.Comment.replace("${r}${n}", "<br />")
It works, but I get slightly different HTML in the email preview in /Admin/Orders/Email/SendMail.aspx compared to the email that is actually sent (from that preview page or by the system when an order is placed). The preview uses <br></br> (as shown by browser's developer tools), while the actual email just contains <br> (as shown by email client's view source). I don't know if AbleCommerce/.Net/NVelocity is actually generating different HTML, or if the browser/email server/email client are "fixing" the HTML as they prefer.
Hmm.., now I realize spaces at the beginning of lines are collapsed by HTML renderers. Should I figure out how to replace them with " "

?