Reputation: 35
I have 8 feature products added in my settings_schema.json . I want to output them by for loop by adding number on the end of settings.feature_product[incrementing integer]
This is my settings schema
{
"type": "product",
"id": "feature_product1",
"label": "Feature Product 1"
},
{
"type": "product",
"id": "feature_product2",
"label": "Feature Product 2"
},
{
"type": "product",
"id": "feature_product3",
"label": "Feature Product 3"
},
{
"type": "product",
"id": "feature_product4",
"label": "Feature Product 4"
},
{
"type": "product",
"id": "feature_product5",
"label": "Feature Product 5"
},
{
"type": "product",
"id": "feature_product6",
"label": "Feature Product 6"
},
{
"type": "product",
"id": "feature_product7",
"label": "Feature Product 7"
},
{
"type": "product",
"id": "feature_product8",
"label": "Feature Product 8"
}
This is the code in my snippet
{% for i in (1..8) %}
{% if i <= 8 %}
<div class="case_item">
{% assign case_var = 'settings.feature_product' | append: i | strip_html %}
{{ all_products[case_var].title }}
</div>
{% endif %}
{% endfor %}
But it doesn't work :( I tried to print the case_var and the result is.. settings.feature_product1 settings.feature_product2 . . settings.feature_product3
Anyone could help me?
Upvotes: 1
Views: 417
Reputation: 2096
{% for i in (1..8) %}
{% capture productid %}feature_product{{ i }}{% endcapture %}
{% if settings[productid] != '' %}
<div class="case_item">
{% assign productslug = settings[productid] %}
<h3>{{ all_products[productslug].title }}</h3>
<em>{{ all_products[productslug].price | money }}</em>
</div>
{% endif %}
{% endfor %}
Upvotes: 1