0

I have a Data Extension with 3 variables/columns. In my email, i want to display the content of these 3 columns as follow :

Your products :

○ %%ID_Product_A%%

○ %%ID_Product_B%%

○ %%ID_Product_C%%

My customer Mr. Toto only bought the product A and the product C, so I want the display as follow :

Your products :

○ %%ID_Product_A%%

○ %%ID_Product_C%%

What I tried :

  <li style="line-height:200%"><b><span style="font-size:16px;">Your products: </span></b><ul>
   <li>
    <span style="font-size:16px;">%%ID_Product_A%% </span></li><li>
    <span style="font-size:16px;">%%ID_Product_B%% </span></li><li>
    <span style="font-size:16px;">%%ID_Product_C%% </span></li></ul></li>

The fact is that with this code, I made a preview and for my customer Mr Toto, I have the display as follow :

Your products :

○ %%ID_Product_A%%

○ %%ID_Product_C%%

=> It creates a space even if the customer did not have the product B. Whereas I want :

Your products :

○ %%ID_Product_A%%

○ %%ID_Product_C%%

Does someone know how to adapt my code ?

2
  • 2
    You should check for whether the fields are empty, and only show the LI if they are not empty: ampscript.guide/empty Commented Apr 18, 2023 at 12:01
  • thank you Lukas it worked ! :)
    – ayakuza91
    Commented Apr 19, 2023 at 8:10

1 Answer 1

0

As mentioned by Lukas, you can use if else condition to check if a product is null

#1 Code example using if/else

<li style="line-height:200%">
<b><span style="font-size:16px;">Your products: </span></b>
<ul>
%%[
    IF NOT Empty(@ID_Product_A) THEN 
]%% 
<li><span style="font-size:16px;">%%=v(@ID_Product_A)=%%</span></li>
%%[
    ENDIF
]%%
%%[
    IF NOT Empty(@ID_Product_B) THEN 
]%% 
<li>
    <span style="font-size:16px;">%%=v(@ID_Product_B)=%%</span>
</li>
%%[
    ENDIF
]%% 
%%[
    IF NOT Empty(@ID_Product_C) THEN 
]%% 
<li>
    <span style="font-size:16px;">%%=v(@ID_Product_C)=%%</span>
</li>
%%[
    ENDIF
]%% 

#2 Code example using inline iif

%%=IIf(EMPTY(@ID_Product_A),"", Concat("<li><span style='font-size:16px;'>",@ID_Product_A,"</span></li>"))=%%
%%=IIf(EMPTY(@ID_Product_B),"", Concat("<li><span style='font-size:16px;'>",@ID_Product_B,"</span></li>"))=%%
%%=IIf(EMPTY(@ID_Product_C),"", Concat("<li><span style='font-size:16px;'>",@ID_Product_C,"</span></li>"))=%%
2
  • thank you very much, I tried it and it worked ! :)
    – ayakuza91
    Commented Apr 19, 2023 at 8:10
  • @ayakuza91 no worries! please mark the answer accepted so it can help other readers
    – Bo Hu
    Commented Apr 19, 2023 at 9:17

You must log in to answer this question.

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