Solved
how to define and populate the values for an object at each iterated individual array
I'm working on AJO API Triggered Campaigns, well I'm trying to write a logic populate the personalization values from API JSON Payload on a HTML Template using below logic and json paylaod!
Question: help me how to define and populate the value for "name" form below json payload at each iterated individual array level for an example
if countProducts = 1 then i want to print the value of attribute (name) at array level[1] with in the html template in this case the level[1] name value = "Super Socks"
AJO logic:
{% let countProducts = count(context.products) %}
{{#each context.products}}
{%#if countProducts = "0"or countProducts = "null"%}
<p>You have no products to display.</p>
{%else%}
<li>Product: {{this.name}}</li>
{%/if%}
{{/each}}
{%#if (toString(countProducts) = "3" )%}
<li>Product: {{context.products.name}}</li>
{%else%}
<p>You have no products to display.</p>
{%/if%}
Results:
{
"context": {
"products": [
{
"name": "Super Socks",
"price": 10.99,
"sku": "SOCK123"
},
{
"name": "Cool Hat",
"price": 19.99,
"sku": "HAT456"
},
{
"name": "Cozy Scarf",
"price": 15.49,
"sku": "SCARF789"
}
]
}
}
Results:(populated using https://experienceleague.adobe.com/en/apps/journey-optimizer/ajo-personalization?lang=en )
- Product: Super Socks
- Product: Cool Hat
- Product: Cozy Scarf
- Product: