0

I have 12 content blocks (for every month of the year) and would like to change the content on the 1st of every month. How do I accomplish this?

0

I have assumed that you create ContentBlocks for every month and name them with a pattern so you can code it very easily. For the code that is presented below you would need 12 different content blocks that are named:

  • AWESOME_CONTENT_MONTH_1
  • AWESOME_CONTENT_MONTH_2
  • ...
  • AWESOME_CONTENT_MONTH_12

Be aware of the fact that there is a limit of characters when you would use ContentBlockByKey

Code:

%%[
/* Do variable declaration at the top for best practices */ 
var @today, @month, @contentBlockToGet

/* Be aware of the difference between now() and now(1). Especially with VAWP */ 
/* Watch resources list below for Now() */
/* Now delivers the time in CET, which has to be transferred to the right timezone for the user, otherwise there might be problems, Watch resources list below for SystemDateToLocalDate() */ 
set @currentSystemTime = now(1)
set @today = SystemDateToLocalDate(@currentSystemTime)
set @month = DatePart(@today, "M")
set @contentBlockToGet

/* Just to test if Salesforce DatePart is correct :D */
IF @month >= 1 and @month <= 12 THEN
    set @contentBlockString = Concat("AWESOME_CONTENT_MONTH_",@month)
ENDIF
]%%

/* Somewhere Inside the Newsletter/Email */
/* To make it failsafe you can also create default content when your contentblock might not exist you would include additional parameters 
https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/contentblockbyname.htm
https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/contentblockbykey.htm */

%%=ContentBlockByName(@contentBlockString)=%%
/* OR */ 
%%=ContentBlockByKey(@contentBlockString)=%%

Resources:

  • Thank you Johannes - looks good - i will test this and let you know. – REZA Y Jun 28 at 17:21
-2

this below code use for getting 1st of every month try like this based on that you can display the content or post your code here what did try so far

%%[

 set @today = now()
 set @monthOfThisMonth = DatePart(@today, "M")
  set @yearOfThisMonth = DatePart(@today, "Y")
   set @firstDayOfThisMonth = 
  dateparse(concat(@monthOfThisMonth,"/01/",@yearOfThisMonth))
  ]%%
  @today: %%=v(@today)=%%
 <br>@monthOfThisMonth: %%=v(@monthOfThisMonth)=%%
 <br>@yearOfThisMonth: %%=v(@yearOfThisMonth)=%%
 <br>@firstDayOfThisMonth: %%=v(@firstDayOfThisMonth)=%%
  • This answer is not targeting the problem. The questioner wants to change content, he/she does not want to display dates. Atleast thats what the question tells us. Your code therefore offers only the way to get the current month. After that the code should use elseifs with ContentblockBy<ID/Key/Name> – Johannes Schapdick Jun 28 at 6:44
  • @ Johannes Schapdick--> thats why iam asking him post your code here like that ok – pkharries Jun 28 at 6:46
  • This is just not the right blueprint. – Johannes Schapdick Jun 28 at 6:48
  • Thank you - the intent is to display the content blocks that are already built and labeled in an email on the first of every month.. – REZA Y Jun 28 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.