I need to setup in Marketing Cloud Email Studio the Global Template background and content background colors dynamically. I have been trying to find a function to do that using AMPScript but didn't find it.

Is that possible?

  • sure, but what are the rules? on what condition would it decide what should be the background colour?
    – zuzannamj
    Aug 2, 2019 at 7:52
  • Hi CodeRage, the only rule is that the Hex color will be defined in a Data Extension that will store the background color. So when setting up the Emal Template, my AMPScript code will read from this DE the Hex color value. Aug 2, 2019 at 8:33
  • would the data extension store many different colours? if yes, how do you decide which one is supposed to be in that particular template?
    – zuzannamj
    Aug 2, 2019 at 8:36
  • 1
    just depending on the Email Name. In my DE I have two columns: Email Name + Background Color. So, using AMPScript at the begining, I will apply the color to the Email Background. Is that possible ? Aug 2, 2019 at 8:44

1 Answer 1


In below code, replace "Name of your DE holding colours" with the actual name of your Data Extension. Make sure the name under which you save your email, matches exactly the email name in your DE.

@lookupValue = emailname_

set @bgcolor = Lookup("Name of your DE holding colors","Background Color","Email Name", @lookupValue)


<body style="background-color: %%=v(@bgcolor)=%%">
<h1>Hello world!</h1>
  • This might work but there could also be content blocks / layouts in the email that would need to be updated, because they would share the same background color. Some of those blocks cannot be changed with ampscript if you still want to drag layouts with that background color in there. One example would be the Retail3 template from Salesforce. I have not found a solution with ampscript to change the background with one value specified via ampscript. Maybe i create a case for it ;) Aug 2, 2019 at 9:46
  • @JohannesSchapdick I created an email template myself and tested above script, it worked, but agree that doing this for the Salesforce-provided templates might be tricky
    – zuzannamj
    Aug 2, 2019 at 9:48
  • especially changing back to the "template colors" in an email can be tricky aswell ;) Aug 2, 2019 at 9:49
  • Hi Both and thanks for your responses. Johannes, you are right. This is exactly my need , to modify using AMPcript the Salesforce global templates, more than a specfic template of one block. I will open a ticket with suppor to see if it is possible or not. Thanks ! Aug 5, 2019 at 13:12

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.