0

I would like to set the font color to green, black or red based on a data extension. The data extension passes a text string such as:

"Status is active."

"Status will expire soon."

"Status is expired."

I want to look in the data extension for the word active, soon or expired and then set the corresponding color.

<p style="color:__;">@status</p>

  • Such as or is one of the following three texts? – Johannes Schapdick Jun 30 at 17:28
  • Yes, it would be one of the three. Active = Green, soon = black, expired = red. – Anthony_Z Jun 30 at 19:12
3

Use an IF condition statement and assign the colour to a variable then inline the value in the style attribute of your p (or similar) tag. This code assumes your status value from the DE is available as a Data Extension attribute, otherwise use a lookup.

%%[
VAR @color, @status, @msg
SET @status = AttributeValue("status_field")

IF @status == "active" THEN
    SET @color = "#00ff00"  /*green*/
    SET @msg = "Status is active."
ELSEIF  @status == "soon" THEN
    SET @color = "#000000"  /*black*/
    SET @msg = "Status will expire soon."
ELSEIF  @status == "expired" THEN
    SET @color = "#ff0000"  /*red*/
    SET @msg = "Status is expired."
ELSE
    SET @color = "#0000ff"  /*default to blue*/
    SET @msg = "Status is not set."
ENDIF
]%%

<p style="color:%%=v(@color)=%%;"> %%=v(@msg)=%% </p>

  • Thanks, this works. – Anthony_Z Jul 9 at 2:55

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.