Issue with foreach loops inside HTML tables

  • 1
  • Problem
  • Updated 2 years ago
  • Solved
Archived and Closed

This conversation is no longer open for comments or replies and is no longer visible to community members. The community moderator provided the following reason for archiving: EOL CLEANUP

I'm trying to get a table of items/prices to display in an automated email.  Whenever I add a looping structure within a table, something like the below in an HTML block of a blank template it doesn't work.

[% foreach context:event:line_items as item %]
<tr><td>[% context:item:inv_no %]</td><td>[% context:item:price %]</td></tr>
[% endforeach %]

All I get is the table header.  If I remove the tr/td tags in the body then it displays the items and prices, but not formatted or in my table cells as intended.  It seems the tags are confusing the loop logic.  I've tried various other options like using a non-HTML block and the code edit button but then it tries to be too smart about what it thinks I'm doing and moves the endforeach just after the foreach and it loses what I'm trying to do.

If there is a different way about this please let me know or provide some working examples.  So far I've not found much in the way of examples other than a simple loop with no HTML inside the foreach loop.
Photo of Avanti Press

Avanti Press

  • 1 Post
  • 0 Reply Likes

Posted 2 years ago

  • 1
Photo of Zach Sharpe

Zach Sharpe, Employee

  • 290 Posts
  • 32 Reply Likes

We wouldn't be able to support any custom HTML but I'm happy to hopefully grant some direction here.

Looping logic would not be valid syntax for our personalization brackets (the [% x x %] format). For more on what you *can* do with these personalization tags feel free to have a look at our resource center article here:

Tables are certainly insertable as well. While these tend to be unpredictable in emails, you would select the insert button in the text editor toolbar and select 'table' from there. More on this can be found here:

Lastly, more on adding HTML to your mailing can be found here:

I hope this helps give some direction to what you are looking to do!