Leveraging variables calculated in content block in Email Body | Community
Skip to main content
Level 2
June 8, 2022
Solved

Leveraging variables calculated in content block in Email Body

  • June 8, 2022
  • 1 reply
  • 1258 views

Hi all,

Context:

Transactional email through Message Center needing values calculated, mainly for date formatting purposes. There are multiple places where this is needed and in different formats.

Question:

Can all the variables be defined in a single content block and called in the body of the Email like in Adobe Campaign, e.g., <%= variable_name %>? Or do you have to create a content block for each instance?

Example: The bold text below needs to be reformatted from a single attribute from the payload. 

in payload: event date: 2022-06-07T12:52:09

in Email Body: 

June 07, 2022 * Location * 12:52

tracking url parameter: JUN:2022

 

Currently, I have created 3 separate content blocks for each displayed date / time. But having to create multiple content blocks for each Email could get unmanageable and wanted to understand if this can be consolidated, without having to do the entire email in the content block. 

 

Appreciate your help in advance,

Jim

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by JimXue

Turns out, you can do exactly that. Do the calculations in the content block. Include the content block in the body of the email, and use <% document.write(<variable name>); %> to render the variables in the email

1 reply

Adobe Employee
June 9, 2022

Hi @jimxue 

This is the code you could use to format dates in a content block and then use the content block in the delivery

The date was formatted in the following way: (Monday 31 january 2010). Using different %D %B %4Y as format will result in different result...what format do you need?

<%
var utcTime = new Date(context.rtEvent.ctx.yourDate);

if (utcTime != undefined && utcTime != "")
{
var sDay = formatDate(utcTime, "%Al", "America/Chicago");
var sDate = formatDate(utcTime, "%D %B %4Y", "America/Chicago");
document.write(sDay + ", " + sDate);
}
else
document.write("");

 

Hope this helps,

Thanks

Denis

JimXueAuthor
Level 2
June 9, 2022

Hi @costa_n11,

Thank you for replying. Yes, I have similar code in a content block already. But do you know if you are able to write the code for all three formats, and call the variable in the Email body. 

For example:

in content block--

var sDay = formatDate(utcTime, "%Al", "America/Chicago");
var sDate = formatDate(utcTime, "%D %B %4Y", "America/Chicago");

in Email code

<% document.write(sDay); %>

<% document.write(sDate); %>

after including the content block somewhere in the email of course?

 

Thanks!

Jim

JimXueAuthorAccepted solution
Level 2
June 13, 2022

Turns out, you can do exactly that. Do the calculations in the content block. Include the content block in the body of the email, and use <% document.write(<variable name>); %> to render the variables in the email