2017-08-09 2 views
1

同様の機能を持つ製品タグを持つ製品ページに製品の詳細/仕様表を表示するためのシステムを作成しましたサプライテーマのグループ化されたフィルタタグ(例: 「Brand_Philips」というタグが付いた製品は、最初の列が「Brand」で、2番目の「Philips」である行がテーブルに自動的に追加されます。奇妙なShopify液体Forloopの動作 - Forloopタグ内のForloopを使用すると、ページがうまくいきません

テーマsettings_schema.jsonに入力を追加して、クライアントが詳細を追加/削除して並べ替えることができるようにしました。今は、新しい設定をループして一致するものがあるかどうかを確認するだけですタグを追加してテーブルに追加しますが、何らかの理由で、タグループ内の詳細をループするときにすべてうまく動作し、詳細内のタグをループするときにページ全体が乱れることがあります。

ここに私のコードです:私はこのコードを書いた、製品ページで

{ 
    "name": "Sort Product Details", 
    "settings": [ 
    { 
     "type": "text", 
     "label": "Type the product detail tags in a comma-separated list.", 
     "id": "product_details", 
     "info": "List items must be identical to the tag prefixes (no underscore), and have no spaces between commas.ie. Brand,Avarage Lifetime,Watts,Volts" 
    } 
    ] 
} 

:settings_schema.jsonで

{% assign marker = '_' %} 
{% assign productDetails = settings.product_details | split: ',' %} 
{% assign found = false %} 
{% for tag in product.tags %}        <!-- The tags loop --> 
    {% for detail in productDetails %}      <!-- The details loop --> 
    {% if tag contains marker and tag contains detail %} 
     {% if found == false %} 
     {% assign found = true %} 
     <hr> 
     <h3>Product Details:</h3> 
     <table class="table-striped"> 
     {% endif %} 
     {{ tag | replace: marker, ': </strong></td><td>' | prepend: '<tr><td><strong>' | append: '</td></tr>' }} 
     {% if found and forloop.last %}</table>{% endif %} 
    {% endif %} 
    {% endfor %} 
{% endfor %} 

お知らせタグループ内のIループの詳細ことなく、私が詳細ループ内のタグをループすると、私のページはすべてうんざりしてしまいます。

enter image description here

そして、ここに私のページには、詳細ループ内のIループのタグ際にどのように見えるかです::

は、ここに私のページが正常にどのように見えるかだ

enter image description here 理由は、私はループにそれをしたいですタグは、クライアントが詳細を並べ替えることができるようにしたい - そして、アルファベット順に表示するべきではない - タグループが動作する方法です。

ありがとうございます!

Martin。

答えて

2

Shopify forumsでこの質問をしたところ、私は答えを出してここで共有したいと思います。

そのすべてが台無ししまった理由は終了</table>タグがこれだけのコード{% if found and forloop.last %}</table>{% endif %}とループの最後に添加し、細部に含まれているタグだけをレンダリングするとき、それは最後のタグに到達したことがないということです。タグループは詳細ループ内にあり、クロージング</table>タグは詳細ループの最後に追加されていることを

{% assign marker = '_' %} 
{% assign productDetails = settings.product_details | split: ',' %} 
{% assign found = false %} 
{% for detail in productDetails %} 
    {% for tag in product.tags %} 
    {% if tag contains marker and tag contains detail %} 
     {% if found == false %} 
     {% assign found = true %} 
     <hr> 
     <h3>Product Details:</h3> 
     <table class="table-striped"> 
     {% endif %} 
     {{ tag | replace: marker, ': </strong></td><td>' | prepend: '<tr><td><strong>' | append: '</td></tr>' }} 
    {% endif %} 
    {% endfor %} 
    {% if found and forloop.last %}</table>{% endif %} 
{% endfor %} 

注:

だからここに私の固定コードです。

関連する問題