Applay transformation in email template

Stefan Sturm asked on March 12, 2016 12:23


i'm trying to create a dynamic email template and have problems to get the data.

My code (sample):

        // Create email
        var email = new CMS.EmailEngine.EmailMessage();
        email.EmailFormat = CMS.EmailEngine.EmailFormatEnum.Both;
        email.From = template.TemplateFrom;
        email.Recipients = recipients;
        email.Subject = template.TemplateSubject;

        // Add parameters to MacroResolver
        var mcr = MacroResolver.GetInstance();
        mcr.SetNamedSourceData("Name", name);
        mcr.SetNamedSourceData("Email", email);
        mcr.SetNamedSourceData("Telefon", phone);
        mcr.SetNamedSourceData("Firmenname", companyName);
        mcr.SetNamedSourceData("WCCID", wccCheck.ID.ToString());

        // Send Email

So how can i apply a transformation to this:

        {% "MacroResolver".ApplyTransformation("myTransformation") %} ??

And at least how should the transformation look like:

        <div>{%# Eval("..??..") %}</div>
        <div>{%# Eval("..??..") %}</div>

Thanks in advice Stefan

Recent Answers

Anton Grekhovodov answered on March 13, 2016 18:06

Hi Stefan,

You have 3 mistakes in your code.

1) You call the method for string "MacroMethod", but you need to call this method for object which data you want to show, e.g. CurrentUser.ApplyTransformation. And you can show all properties of the object in the transformation

2) You can apply transformations of the Text/XML and HTML type via macro expressions. It means that you can use K# syntax to show object properties in the transformation, e.g. for example above to show user first name: {% FirstName %}. But you wrote {% #Eval() %} this is wrong construction, because you mixed K# syntax and ASPX syntax.

Please, see this link

3) If you add some custom fields to MacroResolver, you can show this fields without transformation in email template. For your code it will be:

<div>{% Name %}</div>
<div>{% Email %}</div>
<div>{% Telephone %}</div>

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.