0

I am using the following code to output data in an email to a dynamic table where the number of table rows varies depending on the data. As the code stands it works correctly however when i save it in Marketing Cloud (Email) it moves the main AMPScript code above the table tag causing the AMPScript to break and output the header row for each data row which i dont want.

Is there a way to correct this?

<table>
  <tr>
    <td><strong>Name</strong></td>
    <td><strong>ID</strong></td>
    <td><strong>Amount</strong></td>
  </tr>
  %%[var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i 
  set @lookupValue = AttributeValue("_SubscriberKey") /* value from attribute or DE column in send context */ 
  set @numRowsToReturn = 0 /* 0 means all, max 2000 */ 
  set @rows = LookupOrderedRows("ExampleDE",@numRowsToReturn,"Name, ID, Amount", "Subscriber Key", @lookupValue) 
  set @rowCount = rowcount(@rows) if @rowCount > 0 then for @i = 1 to @rowCount do var @DEColumn1, @DEColumn2, @DEColumn3,
  set @row = row(@rows,@i) /* get row based on counter */ 
  set @DEColumn1 = field(@row,"Name") 
  set @DEColumn2 = field(@row,"ID") 
  set @DEColumn3 = field(@row,"Amount") ]%%
  <tr>
    <td> %%=v(@DEColumn1)=%%</td>
    <td> %%=v(@DEColumn2)=%%</td>
    <td> %%=v(@DEColumn3)=%%</td>
  </tr>
  %%[ next @i ]%%
</table>
%%[ else ]%% 
                %%[ endif ]%%
<p>....</p>```


  • Have you tried placing html comments around the AMPScript? – thechrishaddad Feb 12 at 2:22
  • 1
    I'd recommend using HTML-only content blocks. – Adam Spriggs Feb 12 at 3:39
1

It sounds like you may be housing this code within a free-form content block. If so, the wysiwyg editor has been known to alter or move scripting. Try using your code within an HTML-only content block instead.

| improve this answer | |
  • 1
    Thanks moving it to the HTML only block has fixed it – cocopopps Feb 12 at 20:57

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.