So I have buttons with MANY different background colors and I want to be able to have a single source of truth for the color. If I change the color at the SOURCE it will apply to all the emails that have that button and I know that you can use ampscript to do this.

I was thinking of having different content block's with just the color code as text inside, then calling the ID of that content block to insert into the HTML like below so if I want to change the original color - I can just go to the content block and edit the text. Is this a good route to go?

<table style="background-color:%%=ContentBlockbyId("384201")=%%" bgcolor="%%=ContentBlockbyId("384201")=%%">Button Text </table>

1 Answer 1


Your option is a possible solution, but honestly this seems like a significant waste of resources and processing. I would look at storing the value inside of a data extension and doing a lookup to set the button color.

So you would create a DE like this:

Type     |    CSS
Button 1 |  #AAAAAA
Button 2 |  #AAFFAA

Then inside your email, at the top, you would set the color var inside an AMPscript block:

  set @btnColor = Lookup(@myDE, "CSS", "Type", "Button 1") 

Then for each of your buttons, you would declare them like so:

<table style="background-color:%%=v(@btnColor)=%%" bgcolor="%%=v(@btnColor)=%%">Button Text </table>

and depending on the 'Type' you declare in the top block, will set the color in the buttons.

You can also set multiple color options with multiple vars with lookups for different types.

  • THanks alot Gortonington - very helpful. Out of curisoty, was my syntax wrong? "<table style="background-color:%%=ContentBlockbyId("384201")=%%" You wrote "%%=v(@btnColor)=%%" - so I guess my syntax was wrong? I should have wrote it like set@btncolor =ContentBlockbyId("384201")= in a VAR then inserted that var %%=v(@btnColor)=%% into the HTML? THanks again for the help. I was also thinking maybe storing the colors inside an ampscript block as separate varaibles?
    – GS65
    May 20, 2020 at 7:20
  • Question: "AMPscript block" is that a specific type of content block or it that just "edit the raw HTML" and add this? Dec 9, 2021 at 9:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .