Pass HTML in message token - WorkflowMessageService

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Passing HTML string in message token not work - WorkflowMessageService.

Email received like below

--------------------------------------------------------------------
Dear Sir/ Madam,

For your records, the information you submitted was:

<tr><td style='width: 100%;' colspan='2'><table cellpadding='5' cellspacing='0' border='1' style='background-color: whitesmoke;font-size: 13px;border-collapse: collapse;'><tbody><tr><th style='background-color: #ddd;'>Quantity</th><th style='background-color: #ddd;'>Electrical installer's company name</th><th style='background-color: #ddd;'>Purchase date</th><th style='background-color: #ddd;'>Purchase Date</th><th style='background-color: #ddd;'>Product SKU code</th></tr><tr><td>5</td><td>test</td><td>12/10/2017 11:25:30</td><td>13/10/2017 11:25:30</td><td>0501C</td></tr></tbody></table></td></tr>

Kind regards,

Store Name
6 years ago
You will need a Misc. plugin or nopCommerce customization to allow HTML for a standard token.

1. Create a class, derive it from MessageTokenProvider and override the method where your token is initialized. You should use Token(string key, object value, bool neverHtmlEncoded) where neverHtmlEncoded is true.

2. Replace IMessageTokenProvider dependency with your new class. You can do it in nopCommerce source code (not recommended) or in a plugin.
6 years ago
darshan.shah wrote:
Passing HTML string in message token not work - WorkflowMessageService.

Email received like below

--------------------------------------------------------------------
Dear Sir/ Madam,

For your records, the information you submitted was:

<tr><td style='width: 100%;' colspan='2'><table cellpadding='5' cellspacing='0' border='1' style='background-color: whitesmoke;font-size: 13px;border-collapse: collapse;'><tbody><tr><th style='background-color: #ddd;'>Quantity</th><th style='background-color: #ddd;'>Electrical installer's company name</th><th style='background-color: #ddd;'>Purchase date</th><th style='background-color: #ddd;'>Purchase Date</th><th style='background-color: #ddd;'>Product SKU code</th></tr><tr><td>5</td><td>test</td><td>12/10/2017 11:25:30</td><td>13/10/2017 11:25:30</td><td>0501C</td></tr></tbody></table></td></tr>

Kind regards,

Store Name



Look at Nop.Services.Messages.Token class - you pass in a boolean arg in constructor to indicate "neverHtmlEncoded" - in the case of this token, you would want to set to "true" so the HTML is properly rendered.  For an example of how this is used see the ProductListToHtmlTable function in MessageTokenProvider class.

eg:


tokens.Add(new Token("Order.Product(s)", ProductListToHtmlTable(order, languageId, vendorId), true));


Hope that helps!
6 years ago
Mnay thanks!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.