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

metafield_text フィルター(メタフィールドをテキスト形式で抽出)

メタフィールドの値をテキスト形式で取得するフィルター。テキスト、参照、日付、価格、リストなど各メタフィールド型の値を人間が読める形式に自動変換する。

用途
商品詳細ページでメタフィールドに保存した用量・成分・評価値などをテキスト表示したいとき。特にメタオブジェクト参照型の場合、フィールド指定で特定項目だけを抽出できる。
設置場所
商品テンプレートや商品セクション内で `{{ product.metafields.namespace.key | metafield_text }}` の形で使う。メタオブジェクト参照型の場合は `{{ product.metafields.namespace.key | metafield_text: field: 'フィールド名' }}` のように field パラメータを指定する。
注意点
list 型メタフィールドは `list.single_line_text_field` と `list.metaobject_reference` のみ対応。メタオブジェクト参照型に field パラメータを使う場合、参照先メタオブジェクトの single_line_text_field 型フィールドのみ指定可能で、それ以外の型を指定するとエラーになる。weight・volume・dimension 型の小数値は小数第2位で自動丸めされ、末尾の 0 は削除される(例:2.00 → 2)。money 型はストア通貨設定に従い HTML 形式で出力される。
タグ:metafieldmetaobjecttext-conversiondata-extractionfilter

仕様

70 行 / json
{
  "category": "metafield",
  "deprecated": false,
  "deprecation_reason": "",
  "description": "> Note:\n> The `metafield_text` filter doesn't currently support list metafields other than `list.single_line_text_field` and `list.metaobject_reference`.",
  "parameters": [
    {
      "description": "Specifies which field should be used. Only applicable to types `list.metaobject_reference` and `metaobject_reference`.",
      "name": "field",
      "positional": false,
      "required": false,
      "types": [
        "string"
      ]
    }
  ],
  "return_type": [
    {
      "type": "string",
      "name": "",
      "description": "",
      "array_value": ""
    }
  ],
  "examples": [
    {
      "name": "Basic types",
      "description": "The following outlines the output for each metafield type:\n\n| Metafield type | Output |\n| --- | --- |\n| `single_line_text_field` | The metafield text. |\n| `multi_line_text_field` | The metafield text. |\n| `page_reference` | The page title. |\n| `product_reference` | The product title. |\n| `collection_reference` | The collection title. |\n| `variant_reference` | The variant title. |\n| `file_reference` | The file URL. |\n| `number_integer` | The number. |\n| `number_decimal` | The number. |\n| `date` | The date. |\n| `date-time` | The date and time. |\n| `url` | The URL. |\n| `json` | The JSON. |\n| `boolean` | The boolean value. |\n| `color` | The color value. |\n| `weight` | The weight value and unit.<br><br>If the value is a decimal with more than two places, then it'll be formatted to have a precision of two with trailing zeros removed. |\n| `volume` | The volume value and unit.<br><br>If the value is a decimal with more than two places, then it'll be formatted to have a precision of two with trailing zeros removed. |\n| `dimension` | The dimension value and unit.<br><br>If the value is a decimal with more than two places, then it'll be formatted to have a precision of two with trailing zeros removed. |\n| `rating` | The rating value. |\n| `list.single_line_text_field` | The metafield values in sentence format.<br><br>For example, if you had the values `Toronto`, `Ottawa`, and `Vancouver`, then the output would be:<br><br>`Toronto, Ottawa, and Vancouver` |\n| `money` | The money value, formatted using the store's [**HTML with currency** setting](https://help.shopify.com/manual/payments/currency-formatting). |\n| `rich_text_field` | The rich text value as simple text. |\n",
      "syntax": "",
      "path": "/products/health-potion",
      "raw_liquid": "{{ product.metafields.information.dosage | metafield_text }}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": false
    },
    {
      "name": "Complex types",
      "description": "\nThe following metafield types produce different output depending on the provided `field` parameter:\n\n- [`list.metaobject_reference`](/docs/api/liquid/filters/metafield_text#metafield_text-list.metaobject_reference)\n- [`metaobject_reference`](/docs/api/liquid/filters/metafield_text#metafield_text-metaobject_reference)\n",
      "syntax": "",
      "path": "/products/health-potion",
      "raw_liquid": "",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": false
    },
    {
      "name": "list.metaobject_reference",
      "description": "Outputs the list of metaobjects in sentence format. The required `field` parameter specifies which field should be rendered for each metaobject. The `field` parameter can reference only metafields of type `single_line_text_field`.\n",
      "syntax": "metafield | metafield_text: field: string",
      "path": "/products/health-potion",
      "raw_liquid": "{{ product.metafields.information.ingredients | metafield_text: field: 'name' }}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": false
    },
    {
      "name": "metaobject_reference",
      "description": "Outputs the metafield text for the metaobject field specified by the required `field` parameter. The `field` parameter can reference only metafields of type `single_line_text_field`.\n",
      "syntax": "metafield | metafield_text: field: string",
      "path": "/products/health-potion",
      "raw_liquid": "{{ product.metafields.information.primary_ingredient | metafield_tag: field: 'name' }}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": false
    }
  ],
  "summary": "Generates a text version of the data from a [`metafield` object](https://shopify.dev/docs/api/liquid/objects/metafield).",
  "syntax": "metafield | metafield_text",
  "name": "metafield_text"
}

出典・ライセンス

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