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

size フィルター(文字列・配列の要素数を取得)

文字列の文字数、または配列に含まれる要素の個数を返すフィルター。

用途
コレクション内の商品数が一定数以上かどうかを判定して表示内容を切り替えたり、商品タイトルの長さに応じてスタイルを調整したいとき。
設置場所
Liquid テンプレート内で `{{ value | size }}` の形で使用。条件分岐の中では `{{ array.size }}` とドット記法で直接参照することも可能。
注意点
文字列サイズはバイト数ではなく文字数として計算されるため、日本語や絵文字も1文字としてカウントされる。配列が空または nil の場合は 0 を返す。ドット記法での参照は Liquid タグ内の条件式では機能するが、フィルターチェーン内では `| size` フィルター形式で使う。
タグ:arraystringsizecountnumber

仕様

40 行 / json
{
  "category": "array",
  "deprecated": false,
  "deprecation_reason": "",
  "description": "The size of a string is the number of characters that the string includes. The size of an array is the number of items\nin the array.",
  "parameters": [],
  "return_type": [
    {
      "type": "number",
      "name": "",
      "description": "",
      "array_value": ""
    }
  ],
  "examples": [
    {
      "name": "",
      "description": "",
      "syntax": "",
      "path": "/collections/sale-potions",
      "raw_liquid": "{{ collection.title | size }}\n{{ collection.products | size }}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": false
    },
    {
      "name": "Dot notation",
      "description": "You can use the `size` filter with dot notation when you need to use it inside a tag or object output.\n",
      "syntax": "",
      "path": "/collections/sale-potions",
      "raw_liquid": "{% if collection.products.size >= 10 %}\n  There are 10 or more products in this collection.\n{% else %}\n  There are less than 10 products in this collection.\n{% endif %}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": false
    }
  ],
  "summary": "Returns the size of a string or array.",
  "syntax": "variable | size",
  "name": "size"
}

出典・ライセンス

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