Liquid Snippets by ALSEL
📘 公式リファレンス🔧 リファレンス/フィルター初級

where フィルター(配列を条件で絞り込み)

配列内のオブジェクトから、指定したプロパティが特定の値を持つ項目のみを抽出するフィルター。ブール値プロパティの場合は値の指定を省略して true 判定できる。

用途
コレクションから特定ベンダーの商品だけを取り出したり、販売可能な商品のみをループで表示したりするときに使う。
設置場所
Liquid テンプレート内で `{{ collection.products | where: 'vendor', 'ベンダー名' }}` または `{{ collection.products | where: 'available' }}` の形で使用する。result を変数に保存して後続処理で活用するのが一般的。
注意点
配列のオブジェクトに指定したプロパティが存在しない場合、その項目は結果に含まれない。値の比較は完全一致を要求するため、部分一致や大文字小文字を区別しない検索には向かない。ブール値プロパティで true を絞り込む場合は値引数を省略するが、false で絞り込みたいときは where フィルターでは不可能なため、代わりに if で条件分岐させる。
タグ:arrayfilterconditioncollectionproduct

仕様

40 行 / json
{
  "category": "array",
  "deprecated": false,
  "deprecation_reason": "",
  "description": "This requires you to provide both the property name and the associated value.",
  "parameters": [],
  "return_type": [
    {
      "type": "array",
      "name": "",
      "description": "",
      "array_value": "untyped"
    }
  ],
  "examples": [
    {
      "name": "",
      "description": "",
      "syntax": "",
      "path": "/collections/all",
      "raw_liquid": "{% assign polina_products = collection.products | where: 'vendor', \"Polina's Potent Potions\" %}\n\nProducts from Polina's Potent Potions:\n\n{% for product in polina_products -%}\n  - {{ product.title }}\n{%- endfor %}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": true
    },
    {
      "name": "Filter for boolean properties with a `true` value",
      "description": "You can filter for items that have a `true` value for a boolean property. This requires you to provide only the property name.\n",
      "syntax": "",
      "path": "/collections/all",
      "raw_liquid": "{% assign available_products = collection.products | where: 'available' %}\n\nAvailable products:\n\n{% for product in available_products -%}\n  - {{ product.title }}\n{%- endfor %}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": true
    }
  ],
  "summary": "Filters an array to include only items with a specific property value.",
  "syntax": "array | where: string, string",
  "name": "where"
}

出典・ライセンス

License:
MIT

このコードは Shopify 著作の MIT ライセンスソースです。 原本の著作権は Shopify が保有します。日本語訳は ALSEL によるものです。

関連項目

📘 公式リファレンス🔧 リファレンス/フィルター初級

avatar フィルター(顧客アバター画像HTML生成)

顧客アバターが存在する場合、それを表示する HTML タグを生成するフィルター。customer オブジェクトに対して使用する。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

default_errors フィルター(フォーム送信エラーを日本語化)

form.errors の各エラーコードに対応する既定のエラーメッセージを自動生成するフィルター。フォーム送信時の入力値不正や必須項目空白などのエラーを言語別に出力する。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

date フィルター(日付を指定形式でフォーマット)

日付値を指定されたフォーマット文字列に従って整形する。フォーマット文字列が空の場合は元の値がそのまま返される。入力が日付に変換できない場合も元の値が返される。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

payment_terms フィルター(Shop Pay分割払いバナーを生成)

product フォームまたは cart フォームに対して使用し、Shop Pay の分割払いオプションを表示するための HTML を生成するフィルター。顧客が購入時に分割払いプランを選択できるようにする。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

abs フィルター(数値の絶対値を取得)

負の数を正の数に変換する。数値の絶対値(ゼロからの距離)を返すフィルター。

📁 theme-liquid-docs·MIT·30
📘 公式リファレンス🔧 リファレンス/フィルター初級

append フィルター(文字列の末尾に追加)

文字列の末尾に別の文字列を連結するフィルター。URL パスの結合やテキストの接尾辞追加に使う。

📁 theme-liquid-docs·MIT·30