I have an Order Confirmation email that lists out the order items. The DE for the email send has a text field for the order items, which stores a json array of the items, as below:
[
{"ProductImageUrl":"www.xyz.com/productaimage","ProductName":"Product A","ProductPrice":"$20"},
{"ProductImageUrl":"www.xyz.com/productbimage","ProductName":"Product B","ProductPrice":"$30"},
{"ProductImageUrl":"www.xyz.com/productcimage","ProductName":"Product C","ProductPrice":"$40"},
{"ProductImageUrl":"www.xyz.com/productdimage","ProductName":"Product D","ProductPrice":"$50"}
]
AMPscript using DataObject parses these out into items to be repeated in the email. All is working fine.
Importantly I am using a pre-built custom content block for the repeat, which is referenced within the #each tags. This content block has the image on the left and text details on the right:
Current state:
{{#each ItemsData}}
%%=ContentBlockById("1234")=%%
{{/each}}
Which is effectively this:
%%=ContentBlockById("1234")=%%
%%=ContentBlockById("1234")=%%
%%=ContentBlockById("1234")=%%
%%=ContentBlockById("1234")=%%
Which renders like...
____________________________________
| | |
| PRODUCT A IMAGE | Product A Name |
| | Product A Price |
|_________________|__________________|
____________________________________
| | |
| PRODUCT B IMAGE | Product B Name |
| | Product B Price |
|_________________|__________________|
____________________________________
| | |
| PRODUCT C IMAGE | Product C Name |
| | Product C Price |
|_________________|__________________|
____________________________________
| | |
| PRODUCT D IMAGE | Product D Name |
| | Product D Price |
|_________________|__________________|
However, I now want to use two blocks, where the second one is reversed (ie text details on the left and image on the right) - basically the list of products alternates between block A and block B, so on. Eg:
{{#each ItemsData}}
%%=ContentBlockById("1234")=%%
%%=ContentBlockById("5678")=%%
{{/each}}
Which is effectively this:
%%=ContentBlockById("1234")=%%
%%=ContentBlockById("5678")=%%
%%=ContentBlockById("1234")=%%
%%=ContentBlockById("5678")=%%
To render this:
____________________________________
| | |
| PRODUCT A IMAGE | Product A Name |
| | Product A Price |
|_________________|__________________|
____________________________________
| | |
| Product B Name | PRODUCT B IMAGE |
| Product B Price | |
|_________________|__________________|
____________________________________
| | |
| PRODUCT C IMAGE | Product C Name |
| | Product C Price |
|_________________|__________________|
____________________________________
| | |
| Product D Name | PRODUCT D IMAGE |
| Product D Price | |
|_________________|__________________|
Is this possible to do using my current setup? I'm not sure how to approach this. I have a feeling I might need to count rows and then check for an odd/even rowCount number, but hoping there is an easier way.
Thanks