Skip to main content
abhinav99
Level 4
Oct 11, 2022 10:11 PM UTC
Solved

Conditional Statement in transactional message center

Hi team,

We have a use case where we have to use conditional statements (if, else and maybe a for loop as well) in a transactional message center email template.

 

Is it possible to do so, can we use conditional statements in the transactional message center email template?

If yes, please provide some examples or documentation for the same.

 

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
david--garcia
david--garciaAccepted solution
Level 10
Oct 12, 2022 12:48 AM UTC

 

<% var ctx = XML(rtEvent.ctx); %>

<% if (rtEvent.ctx.myValue == true) {%>

display some html block

<%} else { %>

display some another html block

<%}%>

 

 

The approach is basically the same as normal delivery templates, but in transactional you need to define the ctx variable as above.

https://www.linkedin.com/in/david-garcia-uk/ | https://martech.network

3 replies

david--garcia
david--garciaAccepted solution
Level 10
Oct 12, 2022 12:48 AM UTC

 

<% var ctx = XML(rtEvent.ctx); %>

<% if (rtEvent.ctx.myValue == true) {%>

display some html block

<%} else { %>

display some another html block

<%}%>

 

 

The approach is basically the same as normal delivery templates, but in transactional you need to define the ctx variable as above.

Translate
https://www.linkedin.com/in/david-garcia-uk/ | https://martech.network
Level 2
Jan 26, 2023 3:20 PM UTC

Hi @david--garcia @abhinav99  

 

I have been trying to implement your steps but it still doesn't work for me.

Can you suggest what's wrong?

 

Original method
<% if ( toString(rtEvent.ctx.@freeText22).length > 0 ) { %>
<tr>
<td class="mpbx-27" style="font-size:16px; line-height:22px; font-family:'Core Sans C', Helvetica, Arial, sans-serif; font-weight: 400; text-align:left; min-width:auto !important; color:#151515; padding-bottom: 20px;">
<strong>Sources</strong><br />
<%= rtEvent.ctx.@freeText22 %>
</td>
</tr>
<% } %>

 

New method
<% var ctx = XML(rtEvent.ctx); %>
<% if ( rtEvent.ctx.@freeText22 == true ) { %>
<tr>
<td class="mpbx-27" style="font-size:16px; line-height:22px; font-family:'Core Sans C', Helvetica, Arial, sans-serif; font-weight: 400; text-align:left; min-width:auto !important; color:#151515; padding-bottom: 20px;">
<strong>Sources</strong><br />
<%= rtEvent.ctx.@freeText22 %>
</td>
</tr>
<% } %>
<%} else { %>
<%}%>

 

Thanks!!

 

Translate
david--garcia
Level 10
Feb 14, 2023 3:57 PM UTC

Try the below;

 

<% var ctx = XML(rtEvent.ctx); % > <% if (rtEvent.ctx.@freeText22 == true) {% > <tr> <td class = "mpbx-27" style = "font-size:16px; line-height:22px; font-family:'Core Sans C', Helvetica, Arial, sans-serif; font-weight: 400; text-align:left; min-width:auto !important; color:#151515; padding-bottom: 20px;" > <strong> Sources </strong><br / > <%= rtEvent.ctx.@freeText22 % > </td> </tr> <% } else { % > //html something else <%}%>
Translate
https://www.linkedin.com/in/david-garcia-uk/ | https://martech.network