ASPX templates
Version 5.x > ASPX templates > How to resolve multipe special macros. View modes: 
User avatar
Member
Member
BC - 4/9/2011 9:35:01 PM
   
How to resolve multipe special macros.
I'm attempting to pass two macro, value pairs to a email template. I can only get one macro to resolve when passed to form. If I pass one at a time they both work, but when i attempt to pass together only the first one gets resolved. thanks for the advise

      
MacroResolver mcr = new MacroResolver();
mcr.SpecialMacros = new String[,] { { "#articleURL#", Request.QueryString["articleURL"], "#articleName#", Request.QueryString["articleName"] } } ;


User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/11/2011 6:46:21 PM
   
RE:How to resolve multipe special macros.
Hi,

Where exactly are you using this code?
Does it work when you use just one pair in SpecialMacros, or are you using different approach?

Just a note - for obtaining querystring values, you can use QueryHelper.GetString("parameterName", "defaultvalue")

Which version of Kentico CMS do you use?

Thank you in advance for information.

Regards,
Zdenek

User avatar
Member
Member
BC - 4/11/2011 8:33:31 PM
   
RE:How to resolve multipe special macros.
I created a a custom BizForm. In the BizForm i created a new method called viewBiz_OnAfterSave().

It does work when I only use one pair in SpecialMacro, for example the following works.

mcr.SpecialMacros = new String[,] { { "#articleURL#", Request.QueryString["articleURL"] } };


i'm on the following version v5.5.4014 R2

here is the an example for debug of variable. It seems to be sending data to email template, but not replacing the variable with the acutal data.

SpecialMacros = {string[1, 4]}

[0, 0] = "#articleURL#"
[0, 1] = "http://www.environmentalleader.com/2011/03/29/how-to-win-the-fight-against-nimbyism/"
[0, 2] = "#articleName#"
[0, 3] = "How to Win the Fight against NIMBYism"




User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 4/12/2011 1:54:32 AM
   
RE:How to resolve multipe special macros.
Hi,

could you please try to write your code according to following example:


protected void viewBiz_OnAfterSave()
{
EmailMessage msg = new CMS.EmailEngine.EmailMessage();
EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("Blog.NotificationToModerators", null);

MacroResolver mcr = new MacroResolver();
mcr.SpecialMacros = new String[,] { { "#macro#", "text1" },{"#secondmacro#", "text2"} }; //here you can specify text for multiple macros specified in template

msg.EmailFormat = EmailFormatEnum.Both;
msg.From = eti.TemplateFrom;
msg.Recipients = "ivanat@kentico.com";
msg.Subject = eti.TemplateSubject;

EmailSender.SendEmailWithTemplateText(CMSContext.CurrentSiteName, msg, eti, mcr, true);
}


Using above code were both macros resolved correctly.

Inside the template were macros used following way:

<p>
#macro#
#secondmacro#

New blog post comment was added and now is waiting for your approval:
</p>


Best regards,
Ivana Tomanickova

User avatar
Member
Member
BC - 4/12/2011 6:55:48 PM
   
RE:How to resolve multipe special macros.
That worked. My brackets were not right.

thanks for the help