Liquid Snippets by ALSEL
📘 公式リファレンス📦 リファレンス/オブジェクト初級

metafield オブジェクト

商品・コレクション・顧客など各オブジェクトに紐付けたカスタムメタフィールドにアクセスするオブジェクト。単一行テキスト、リッチテキスト、商品参照、日付、JSON、色、寸法など複数の型に対応している。

用途
商品ページで商品のカスタムメタフィールド(例:製造国、推奨用途、カスタム説明文)を表示したいときや、コレクションページで追加の説明情報を出力するときに使う。
設置場所
Liquid テンプレート内で `{{ product.metafields.namespace.key }}` のように参照する。`namespace` と `key` はメタフィールド作成時に定めた名前に置き換える。
注意点
メタフィールドは Shopify 管理画面またはアプリ経由でのみ作成でき、Liquid では作成・編集できない。古い実装の `integer`、`json_string`、`string` 型はメタフィールドフィルターに対応していないため、新規作成時は `number_integer`、`json`、`single_line_text_field` 等の新しい型を使う。日付型は `| date` フィルターで整形する必要がある。
タグ:metafieldcustom-dataproductcollectionreference

仕様

295 行 / json
{
  "access": {
    "global": false,
    "parents": [
      {
        "object": "app",
        "property": "metafields"
      },
      {
        "object": "article",
        "property": "metafields"
      },
      {
        "object": "blog",
        "property": "metafields"
      },
      {
        "object": "collection",
        "property": "metafields"
      },
      {
        "object": "customer",
        "property": "metafields"
      },
      {
        "object": "location",
        "property": "metafields"
      },
      {
        "object": "order",
        "property": "metafields"
      },
      {
        "object": "page",
        "property": "metafields"
      },
      {
        "object": "product",
        "property": "metafields"
      },
      {
        "object": "shop",
        "property": "metafields"
      },
      {
        "object": "variant",
        "property": "metafields"
      }
    ],
    "template": []
  },
  "deprecated": false,
  "deprecation_reason": "",
  "description": "To learn about how to access a metafield on a specific object, refer to [Access metafields](/docs/api/liquid/objects/metafield#metafield-access-metafields).\n\nMetafields support [multiple data types](/apps/metafields/types), which determine the kind of information that's stored\nin the metafield. You can also output the metafield content in a type-specific format using\n[metafield filters](/docs/api/liquid/filters/metafield-filters).\n\n> Note:\n> You can't create metafields in Liquid. Metafields can be created in only the following ways:\n>\n> - [In the Shopify admin](https://help.shopify.com/manual/metafields)\n> - [Through an app](https://shopify.dev/apps/metafields)\n\n> Note:\n> Metafields of type `integer`, `json_string`, and `string` are older implementations that don't have the properties\n  noted on this page, and aren't compatible with metafield filters. To learn more, refer to [Deprecated metafields](/docs/api/liquid/objects/metafield#metafield-deprecated-metafields).",
  "properties": [
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "The following table outlines the value format for each metafield type:\n\n<table>\n  <thead>\n    <tr>\n      <th>Type</th>\n      <th>Returned format</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td>\n        <code>single_line_text_field</code><br><br>\n        <code>multi_line_text_field</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/basics#string\">A string</a></td>\n    </tr>\n    <tr>\n      <td>\n        <code>rich_text_field</code>\n      </td>\n      <td>A field that supports headings, lists, links, bold, and italics</td>\n    </tr>\n    <tr>\n      <td>\n        <code>product_reference</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/objects/product\">A product object</a></td>\n    </tr>\n    <tr>\n      <td>\n        <code>collection_reference</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/objects/collection\">A collection object</a></td>\n    </tr>\n    <tr>\n      <td>\n        <code>variant_reference</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/objects/variant\">A variant object</a></td>\n    </tr>\n    <tr>\n      <td>\n       <code>page_reference</code>\n     </td>\n     <td><a href=\"/docs/api/liquid/objects/page\">A page object</a></td>\n    </tr>\n    <tr>\n      <td>\n        <code>file_reference</code>\n     </td>\n     <td>\n       <a href=\"/docs/api/liquid/objects/generic-file\">A generic_file object</a><br><br>\n       <a href=\"/docs/api/liquid/objects/media\">A media object (images and videos only)</a>\n     </td>\n    </tr>\n    <tr>\n      <td>\n        <code>number_integer</code><br><br>\n        <code>number_decimal</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/basics#number\">A number</a></td>\n    </tr>\n    <tr>\n      <td>\n        <code>date</code><br><br>\n        <code>date_time</code>\n      </td>\n      <td>A date string. To format the string, use the <a href=\"/docs/api/liquid/filters/date\">date</a> filter.</td>\n    </tr>\n    <tr>\n      <td>\n        <code>url_reference</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/basics#string\">A url string</a></td>\n    </tr>\n    <tr>\n      <td>\n        <code>json</code>\n      </td>\n      <td><a href=\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON\">A JSON object</a></td>\n    </tr>\n    <tr>\n      <td>\n       <code>boolean</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/basics#boolean\">A boolean</a></td>\n    <tr>\n      <td>\n        <code>color</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/objects/color\">A color object</a></td>\n    </tr>\n    <tr>\n      <td>\n        <code>weight</code><br><br>\n        <code>volume</code><br><br>\n        <code>dimension</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/objects/measurement\">A measurement object</a></td>\n    </tr>\n    <tr>\n      <td>\n        <code>rating</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/objects/rating\">A rating object</a></td>\n    </tr>\n    <tr>\n      <td>\n        <code>money</code>\n      </td>\n      <td><a href=\"/docs/api/liquid/objects/money\">A money object, displayed in the customer's local (presentment) currency.</a></td>\n    </tr>\n  </tbody>\n</table>",
      "examples": [],
      "return_type": [
        {
          "type": "untyped",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The value of the metafield.",
      "name": "value"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "single_line_text_field",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "multi_line_text_field",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "rich_text_field",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "product_reference",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "collection_reference",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "variant_reference",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "page_reference",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "file_reference",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "number_integer",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "number_decimal",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "date",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "date_time",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "url_reference",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "json",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "boolean",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "color",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "weight",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "volume",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "dimension",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "rating",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "money",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The [type](/apps/metafields/types) of the metafield.",
      "name": "type"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "> Tip:\n> To learn about metafield types, refer to [Metafield types](/apps/metafields/types).",
      "examples": [],
      "return_type": [
        {
          "type": "boolean",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "Returns `true` if the metafield is a list type. Returns `false` if not.",
      "name": "list?"
    }
  ],
  "summary": "A [metafield](/apps/metafields) attached to a parent object.",
  "name": "metafield",
  "examples": [
    {
      "name": "Access metafields",
      "description": "The access path for metafields consists of two layers:\n\n- namespace - A grouping of metafields to prevent conflicts.\n- key - The metafield name.\n\nGiven this, you can access the metafield object with the following syntax:\n\n```liquid\n{{ resource.metafields.namespace.key }}\n```\n",
      "syntax": "",
      "path": "/products/health-potion",
      "raw_liquid": "Type: {{ product.metafields.information.directions.type }}\nValue: {{ product.metafields.information.directions.value }}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": false
    },
    {
      "name": "Accessing metafields of type `json`",
      "description": "The `value` property of metafields of type `json` returns a [JSON object](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON). You can access the properties of this object directly in Liquid, either by name or 0-based index. You can also iterate through the properties.\n",
      "syntax": "",
      "path": "/products/charcoal",
      "raw_liquid": "Temperature: {{ product.metafields.information.burn_temperature.value.temperature }}\nUnit: {{ product.metafields.information.burn_temperature.value['unit'] }}\n\n{% for property in product.metafields.information.burn_temperature.value -%}\n  {{ property.first | capitalize }}: {{ property.last }}\n{%- endfor %}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": false
    },
    {
      "name": "Accessing metafields of type `list`",
      "description": "The `value` property of metafields of type `list` returns an array. You can iterate through the array to access the values.\n",
      "syntax": "",
      "path": "/products/ground-mandrake-root",
      "raw_liquid": "{% for item in product.metafields.information.combine_with.value -%}\n  {{ item.product.title }}\n{%- endfor %}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": true
    },
    {
      "name": "",
      "description": "<br><br> If the list is of type `single_line_text_field`, then you can access the items in the array directly in Liquid using a 0-based index.\n",
      "syntax": "",
      "path": "/products/health-potion",
      "raw_liquid": "First item in list: {{ product.metafields.information.pickup_locations.value[0] }}\nLast item in list: {{ product.metafields.information.pickup_locations.value.last }}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": true
    },
    {
      "name": "Determining the length of a list metafield",
      "description": "The way that you determine the length of a list metafield depends on its type:\n- **[Reference types](/docs/apps/custom-data/metafields/types#reference-types)**: Use the `count` property to determine the list length.\n- **Non-reference types**: These lists are rendered as arrays. Use the [`size`](/docs/api/liquid/filters/size) filter to determine the number of items in the array.\n",
      "syntax": "",
      "path": "/products/health-potion",
      "raw_liquid": "# list.product_reference\nNumber of similar products: {{ product.metafields.information.similar_products.value.count }}\n\n# list.single_line_text_field\nNumber of pickup locations: {{ product.metafields.information.pickup_locations.value.size }}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": true
    },
    {
      "name": "Deprecated metafields",
      "description": "Deprecated metafields are older metafield types with limited functionality. The following metafield types are deprecated:\n\n- `integer`\n- `json_string`\n- `string`\n\nThese metafield types don't have the same metafield object properties mentioned in the previous sections. Instead, they return the metafield value directly.\n\nThe following table outlines the value type for each deprecated metafield type:\n\n| Metafield type | Value type |\n| --- | --- |\n| `integer` | [An integer](/docs/api/liquid/basics#number) |\n| `json_string` | [A JSON object](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON) |\n| `string` | [A string](/docs/api/liquid/basics#string) |\n",
      "syntax": "",
      "path": "/",
      "raw_liquid": "",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": true
    }
  ],
  "json_data": {
    "path": "/products/health-potion",
    "handle": "product.metafields.information.directions",
    "data_from_file": ""
  },
  "return_type": []
}

出典・ライセンス

License:
MIT

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

関連項目

📘 公式リファレンス📦 リファレンス/オブジェクト初級

content_for_header オブジェクト

Shopify が必要とするスクリプト(分析・チェックアウト・言語設定など)をすべて動的に出力するオブジェクト。theme.liquid の <head> タグ内に埋め込む必須要素。

📁 theme-liquid-docs·MIT·20
📘 公式リファレンス📦 リファレンス/オブジェクト中級

metaobjects オブジェクト

ストア全体のメタオブジェクト定義にアクセスするグローバルオブジェクト。個別のメタオブジェクトはタイプとハンドルで参照でき、メタオブジェクト定義のエントリをループで反復処理できる。

📁 theme-liquid-docs·MIT·20
📘 公式リファレンス📦 リファレンス/オブジェクト初級

additional_checkout_buttons オブジェクト

PayPal Express Checkout など、オフサイト決済に対応した外部決済プロバイダーがストアに設定されているかを真偽値で返す。`content_for_additional_checkout_buttons` と組み合わせて、該当するチェックアウトボタンを条件付きで表示する。

📁 theme-liquid-docs·MIT·27
📘 公式リファレンス📦 リファレンス/オブジェクト初級

canonical_url オブジェクト

現在のページの正規 URL を取得するオブジェクト。Google などの検索エンジンに対してどのページ版が正規であるかを指定するために使用する。

📁 theme-liquid-docs·MIT·27
📘 公式リファレンス📦 リファレンス/オブジェクト初級

content_for_index オブジェクト

ホームページに表示するセクションの内容を動的に返すオブジェクト。Liquid インデックステンプレートで必ず使用する。

📁 theme-liquid-docs·MIT·27
📘 公式リファレンス📦 リファレンス/オブジェクト初級

content_for_additional_checkout_buttons オブジェクト

PayPal、Apple Pay、Google Pay など複数の決済プロバイダが有効になっているとき、その決済ボタンを HTML として出力するオブジェクト。`additional_checkout_buttons` で有無を判定したうえで、このオブジェクトで実際のボタンを表示する。

📁 theme-liquid-docs·MIT·27