我在settings_schema.json中添加了8个功能产品。我想通过在settings.feature_product [递增整数]的末尾添加数字来通过for循环输出它们
这是我的设置架构
{
"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"
}
这是我的代码段中的代码
{% 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 %}
但它不起作用:(我试图打印case_var,结果是...... settings.feature_product1 settings.feature_product2 。 。 settings.feature_product3
有人可以帮助我吗?
答案 0 :(得分:1)
{% 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 %}