2016-05-27 63 views
1

我在我的settings_schema.json中添加了8個功能產品。我想通過環路輸出他們通過settings.feature_product的末尾添加數[遞增的整數]旋轉字符串?在Shopify

這是我的設置模式

{ 
    "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

任何人都可以幫助我?

回答

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 %} 
+0

謝謝!它工作酷&熱! –