商品の種類に基づいて商品ページにスニペットとテンプレートを含めるようにしています。しかし、液体は条件付きでスニペットを生成するようには見えません。液体入りのスニペットとテンプレートを含む
私が達成しようとしているものの例:
{% if product.type == 'shoes' %}
{% include 'shoes-template' %}
{% else %}
{% include 'other-template' %}
{% endif %}
商品の種類に基づいて商品ページにスニペットとテンプレートを含めるようにしています。しかし、液体は条件付きでスニペットを生成するようには見えません。液体入りのスニペットとテンプレートを含む
私が達成しようとしているものの例:
{% if product.type == 'shoes' %}
{% include 'shoes-template' %}
{% else %}
{% include 'other-template' %}
{% endif %}
あなたは多くの製品の種類を持っている場合は、代わりに複数のif
とelse if
を使用しての、あなたがアレイとcontains
を使用することができます。 capture
を実行し、文字列 "Liquid error"を検索して、テンプレートが存在するかどうかを確認することもできます。
{% assign types = "shoes, shirts, pants" | split:", " %}
{% if types contains product.type %}
{% assign snip = product.type | append:"-template" %}
{% else %}
{% assign snip = "other-template" %}
{% endif %}
{% capture snip_content %}{% include snip %}{% endcapture %}
{% unless snip_content contains "Liquid error" %}
{% include snip %}
{% endunless %}
何かあります。条件付きの 'include'が動作します。私は多くの場所でそれを使用しています。他の関連コードを共有することはできますか? 'shoes-template'と' other-template'も同じですか? – HymnZ