Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > CustomMacro with html tags View modes: 
User avatar
Member
Member
Ark_IT - 8/18/2010 9:24:41 AM
   
CustomMacro with html tags
Hello!

i made custommacro, in ResolveCustomMacro() method in CMSCustom.cs
it return string.
when macro is used in invoice form - all html tags in string are encoded in &alt; etc..
how can i get clear string, with html tags i made?

Thank you.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 8/18/2010 4:00:40 PM
   
RE:CustomMacro with html tags
Hello,

you can use the encode parameter for the macro to resolve HTML. Please see here: Macro expressions for more details.

Best regards,
Helena Grulichova

User avatar
Member
Member
Ark_IT - 8/19/2010 1:53:01 AM
   
RE:CustomMacro with html tags
Didn`t work...
{#itemsdata|(encode)false#} gives "itemsdata|(encode)false" in invoice! 
and forexample {%order.ordertrackingnumber|(tolower)true%} gives correct data

maybe parameters dont work for custom macros?

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 8/19/2010 5:53:12 AM
   
RE:CustomMacro with html tags
Hello,

I am very sorry. The encode parameter does not work with custom macros. It is by design behavior according to our developers.

For your purpose, you can call an EncodeHTML method on the result in your custom macro.

The API Reference is here: API Reference

Best regards,
Helena Grulichova

User avatar
Member
Member
Ark_IT - 8/19/2010 6:51:51 AM
   
RE:CustomMacro with html tags
It doesnt help.
CMS.GlobalHelper.HTMLHelper.HTMLEncode() - it encodes html tags, but i need them as is, not-encoded.
result of custom macro encodes after, when invoice generates m/b..

so guess i should override OrderInfoProvider.GetInvoice() method in custom provider.
maybe there is another, easier way?

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 8/19/2010 7:24:17 AM
   
RE:CustomMacro with html tags
Hello,

I am not sure what you want to achieve. I meant you want & instead of 'amp;' Is that right?

Could you please tell me more details?


Best regards,
Helena Grulichova

User avatar
Member
Member
Ark_IT - 8/19/2010 8:20:43 AM
   
RE:CustomMacro with html tags
custommacro return string - <tr><td>some text</td></tr>
in invoice it shows like this -
<tr><td style="text-align: left;">some text</td></tr>
(in sourcecode of invoice html)

i want them to be html, not > or something

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/19/2010 11:12:58 AM
   
RE:CustomMacro with html tags
Hi,

Could you please try to adjust your custom macro by adding this statement to your custom macro, right before you return the final string:

sender.AllowParameters = false;

Best Regards,
Ivana Tomanickova

User avatar
Member
Member
Ark_IT - 8/20/2010 1:47:46 AM
   
RE:CustomMacro with html tags
It works!
Thank you very much!

User avatar
Certified Developer 8
Certified Developer 8
richard - 2/18/2012 6:18:14 PM
   
RE:CustomMacro with html tags
Hi Ivana

sender.AllowParameters = false; is no longer available in version 6. Can you please explain how I can output the HTML unencoded in version 6 please.

Cheers

Richard

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 2/20/2012 3:58:38 AM
   
RE:CustomMacro with html tags
Hi,

here is a 6.0 macro example:
 switch (e.Expression.ToLower())
{
case "someexpression":
e.Match = true;
e.Result = "<b>bold text </b>";
break;
}

If you call above macro using {% ProcessCustomMacro("someexpression", "") %} in for example properties of repeater you will get the output:
bold text

In case you will call it using {% ProcessCustomMacro("someexpression", "|(encode)true") %} the output will be:
<b>bold text </b>

It means that you can change the output using the (encode) parameter.

Best regards,
Ivana Tomanickova