1

I am trying to use AMPscript within an HTML email to add an HTML table or not to add the HTML table base on a data extension field that is populated or not. Then placed the %%=v(@dealership1)=%% and %%=v(@dealerships)=%% in the body of the HTML were I would like the table to go.

Example of my code that I have placed in my HTML script tag:

<script>
%%[
    var @dealership2
    var @dealership3
    var @dealership1
    var @dealerships
    set @dealership2 = [dealer_2_name]Lookup("TEST_DATA_coupon", "dealer_2_name", "email_address", AttributeValue("emailaddr"))
    set @dealership3 = [dealer_3_name]Lookup("TEST_DATA_coupon", "dealer_3_name", "email_address", AttributeValue("emailaddr"))

    set @dealership1 = "<table class="dealer-infocontainer" width="210" align="left" style="width:210px;border-spacing: 0px;border: 0; margin: 0px;">
      <tr style="line-height: 100%;">
        <td class="dealer-icon" style="padding: 0 0 0 35px;"> Bla, BLA
          </td>
        </tr>
        <!--<![endif]-->
      </table>"
set @dealerships = "<table class="dealer-infocontainer" width="210" align="left" style="width:210px;border-spacing: 0px;border: 0; margin: 0px;">
        <tr style="line-height: 100%;">
          <td class="dealer-icon" style="padding: 0 0 0 35px;">
<td class="dealer-icon" style="padding: 0 0 0 35px;"> Bla, BLA
          </td>
        </tr>
        <!--<![endif]-->
      </table>"

]%%
%%[IF (@dealership2 AND @dealership3) <= 0  THEN]%%

  %%=v(@dealership1)=%%


%%[ELSE]%%

  %%=v(@dealership2_3)=%% 

%%[ENDIF]%%

</script>
1
  • It just seems to not work correctly. A little new to the AMPscript code thing. Thanks for any light anyone can shine on this.
    – David Mc
    Commented Jul 13, 2017 at 18:49

1 Answer 1

2

You don't need to write the HTML code to variables, you can just put it between the if and else and the else and endif, as you end the AMPscript block with ]%%. Another thing I guess isn't working out is your assignment to @dealership2 and @dealership3. I guess you like to count the retrieved lines? Anyways even if not, the read value directly in front of the Lookup-function call won't work. Furthermore you don't need to add AMPscript to a script-block.

For example this could work:

%%[
    var @dealership2
    var @dealership3
    var @dealership1
    var @dealerships
    set @dealership2 = RowCount(Lookup("TEST_DATA_coupon", "dealer_2_name", "email_address", AttributeValue("emailaddr")))
    set @dealership3 = RowCount(Lookup("TEST_DATA_coupon", "dealer_3_name", "email_address", AttributeValue("emailaddr")))
]%%
%%[IF Add(@dealership2, @dealership3) <= 0  THEN]%%

    <table class="dealer-infocontainer" width="210" align="left" style="width:210px;border-spacing: 0px;border: 0; margin: 0px;">
      <tr style="line-height: 100%;">
        <td class="dealer-icon" style="padding: 0 0 0 35px;">Bla, BLA</td>
      </tr>
        <!--<![endif]-->
      </table>


%%[ELSE]%%

    <table class="dealer-infocontainer" width="210" align="left" style="width:210px;border-spacing: 0px;border: 0; margin: 0px;">
        <tr style="line-height: 100%;">
          <td class="dealer-icon" style="padding: 0 0 0 35px;"></td>
          <td class="dealer-icon" style="padding: 0 0 0 35px;"> Bla, BLA</td>
        </tr>
        <!--<![endif]-->
      </table>

%%[ENDIF]%%
0

You must log in to answer this question.

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