Issue with foreach loops inside HTML tables

  • 1
  • Problem
  • Updated 3 months ago
  • Solved
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.

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

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 3 months ago

  • 1
Photo of Zach Sharpe

Zach Sharpe, Employee

  • 289 Posts
  • 32 Reply Likes
Hello!

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:

https://support.e2ma.net/Resource_Center/Account_how-to/adding-personalization

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:

https://support.e2ma.net/Resource_Center/Account_how-to/using-the-table-editor

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

https://support.e2ma.net/Resource_Center/Account_how-to/using-html-code-in-your-campaign

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

Thanks

Zach