Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Escape html in macro email templates View modes: 
User avatar
Member
Member
eric.savage-clyral - 11/1/2012 10:42:53 AM
   
Escape html in macro email templates
Following on from this thread:
http://devnet.kentico.com/Forums/f65/t32511/Foreach-usage-in-k-macros.aspx

I'm trying to render items in a foreach collection in an email template using the following code:
<b>Active Users</b><br/>
{% foreach(item in users_active) { ResolveMacros("\r\n{%item%\}<br/>\r\n") } %}

The items are rendering correctly, but the html "<br/>" inside the loop is being treated as output text instead of html. How can I escape it so that it renders a new-line instead?

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 11/4/2012 7:41:55 AM
   
RE:Escape html in macro email templates
Hi Eric,

I'm afraid that the only solution in this case is to write your custom macro.

Best regards,
Martin Danko

User avatar
Member
Member
eric.savage-clyral - 11/5/2012 2:05:58 AM
   
RE:Escape html in macro email templates
Thanks - I implemented a custom macro, which was fairly easy, but it doesn't render html.

If I use the following line and put it anywhere in the email template, it produces text, not html:
e.Result = "<h1>My Title</h1>";

Is there some way to render the output as html?

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 11/6/2012 5:47:15 AM
   
RE:Escape html in macro email templates
Hi,

I've tested it again and it's also possible to use (encode)false macro parameter:
{% foreach(item in Documents["/Company"].DocumentName) { ResolveMacros("\r\n{%item%\} new_line <br />\r\n") } |(encode)false%}

Best regards,
Martin Danko

User avatar
Member
Member
eric.savage-clyral - 11/7/2012 3:45:32 AM
   
RE:Escape html in macro email templates
Thanks, the first suggestion there works, as follows:
{% foreach(item in users_active) { ResolveMacros("\r\n{%item%\} <br/>\r\n") } |(encode)false%}

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 11/7/2012 3:52:03 AM
   
RE:Escape html in macro email templates
Hi,

You're welcome. Sorry that I didn't have this option on my mind as first... it was the simplest one.

Best regards,
Martin Danko