Day 19 – Show custom image based on loyalty details

Challenge

https://ampscript30.com/ampscript-challenge-day19/

To show custom image based on subscriber’s loyalty level.

Solution

%%[
SET @fullname = Concat(FirstName, " ", LastName)
SET @loyaltypoints = LoyaltyPoints
SET @loyaltylevel = LoyaltyLevel
IF @loyaltylevel == "Bronze" THEN
    SET @badge = ContentImagebyKey("a6343ceb-e1c5-4e16-9281-c6068884480d")
ELSEIF @loyaltylevel == "Gold" THEN
    SET @badge = ContentImagebyKey("e878bfaf-2f88-44b1-a9b8-60b90b9bd00a")
ELSEIF @loyaltylevel == "Platinum" THEN
    SET @badge = ContentImagebyKey("7fb97a5a-e446-4edc-9aa1-6e127fe17a2c")
ELSEIF @loyaltylevel == "Diamond" THEN
    SET @badge = ContentImagebyKey("d807514e-e249-4b2a-a328-d4f10289a0d8")
ENDIF]%%
%%=v(@badge)=%%

Hello %%=v(@fullname)=%%,

We wanted to remind you that you have accumulated %%=v(@loyaltypoints)=%% travel credits on your account that can be used for your next trip. We encourage you to take advantage of this benefit and redeem your travel credits for your next adventure.

Thank you for choosing our travel company for your travel needs. We look forward to helping you plan your next trip. 

Best regards,
Next Travel 

Preview

Summary

Use the ContentImagebyKey(“Customer Key”) function to retrieve the image to the email content – make sure to use the Customer Key on the image (can be found on the image details). I made a mistake by writing the “ELIF” keyword instead of “ELSEIF” keyword, which disrupted the logic of showing the image based on subscribers’ loyalty level. “ELIF” is the Python syntax, and the correct syntax for AMPscript should be “ELSEIF”.