Solved

Creating re-usable sections with complicated event data structure

  • 12 June 2024
  • 1 reply
  • 41 views

Badge

Hi there!

We’re trying to use the email template editor to build a re-usable section that contains a header and a 2-column table of products from event data. We want to display multiple of these re-usable sections in the same email based on our data.

An example event data structure might look like this:

{
"sections": [
{
"id": 1,
"title": "Example section"
},
{
"id": 2,
"title": "A new section"
}
],
"products": [
{
"id": 1,
"title": "Example product",
"price": 123,
"size": "M",
"image_url": "https://joinbeni.com/example/image/1",
"section_id": "1"
},
{
"id": 2,
"title": "Another product for section 1",
"price": 20,
"size": "S",
"image_url": "https://joinbeni.com/example/image/2",
"section_id": "1"
},
}
"id": 3,
"title": "A product for section 2",
"price": 32,
"size": "XL",
"image_url": "https://joinbeni.com/example/image/3",
"section_id": "2"
}
]
}

Due to our previous email structure we have the data structure “flattened” in separate lists and so ideally we can just re-use this so its backwards compatible. The products follow this custom structure and each section can have up to 4 products.

We followed the advice from 

and have a table per row of products each with two columns. Based on the answer to that community discussion it doesn’t seem like we can use loops but please let me know if I’m wrong there.

Question 1: is it possible to use the available filters to get a list of products for a single section? I’ve been trying to do something like event.products|list_where:"section_id=event.sections.0.id" for use both in display logic and in content of the table cells. Is it possible to insert the value from a variable (e.g. event.sections.0.id) into that list_where filter clause? For example, the display logic of one table might be event.products|list_where:"section_id=event.sections.0.id"|length > 3 and a part of some cell content might be <div>{{ event.products|list_where:"section_id=event.sections.0.id".0.title }}</div>.

If this isn’t possible, we can always change to a nested data structure where each section dict contains a list of it’s products.

Question 2: is it possible to save a section as universal content and set some parent variable from the event data to be used within the section? For example, Jinja/Django templates allow you to use “set” to create a variable and ideally we could do something like “set current_section = event.sections.1” and “set current_product_list = event.products|list_where:"section_id=$event.sections.1.id"” so when we create new sections from that universal content we can simply specify those parent values (e.g. section 0 would have event.sections.0, section 1 would have event.sections.1, etc) and the section itself wouldn’t have to change because it’s referencing those values (e.g. show current_section.title in text box).

Let me know please! Appreciate all the good work and helpful community responses from your team.

icon

Best answer by Taylor Tarpley 25 June 2024, 20:04

View original

1 reply

Userlevel 7
Badge +60

Hi there @timmycron

 

Are you still trying to find a solution to this? 

 

I wonder if any of our partner Champions have created or worked with this type of custom coded section before? @Omar @retention @annasophiefc @DavidV ?

 

-Taylor 

Reply