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

collection オブジェクト

コレクションページで使用する、現在閲覧しているコレクションの情報を格納するオブジェクト。タイトル、説明、メタフィールド、ソートオプション、フィルター設定など。

用途
collection.liquid テンプレートでコレクション名やフィルター機能を表示するとき、またはコレクション内の商品一覧ページで現在のコレクション情報を参照するとき。
設置場所
templates/collection.liquid または sections/main-collection.liquid 内で `{{ collection.title }}`、`{{ collection.description }}`、`{% for option in collection.sort_options %}` のように参照する。
注意点
`collection` オブジェクトは collection.liquid テンプレート内でのみ自動的に利用可能。他のテンプレートで参照する場合は `collections[handle]` でハンドルを指定して取得する。`image` プロパティは Shopify 管理画面のコレクション詳細で設定した画像のみで、商品画像ではない。`current_vendor` と `current_type` は特殊なコレクションページ(/collections/vendors、/collections/types)でのみ値を持つ。
タグ:collectionliquid-objecttemplateproperties

仕様

497 行 / json
{
  "access": {
    "global": false,
    "parents": [
      {
        "object": "collections",
        "property": ""
      }
    ],
    "template": [
      "collection"
    ]
  },
  "deprecated": false,
  "deprecation_reason": "",
  "description": "",
  "properties": [
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "> Tip:\n> To learn about how to create metafields, refer to [Create and manage metafields](/apps/metafields/manage) or visit\n> the [Shopify Help Center](https://help.shopify.com/manual/metafields).",
      "examples": [],
      "return_type": [
        {
          "type": "array",
          "name": "",
          "description": "",
          "array_value": "metafield"
        }
      ],
      "summary": "The [metafields](/docs/api/liquid/objects/metafield) applied to the collection.",
      "name": "metafields"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [],
      "return_type": [
        {
          "type": "number",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The ID of the collection.",
      "name": "id"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The [handle](/docs/api/liquid/basics#handles) of the collection.",
      "name": "handle"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The title of the collection.",
      "name": "title"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The description of the collection.",
      "name": "description"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "The name doesn't include the `collection.` prefix, or the file extension (`.json` or `.liquid`).\n\n If a custom template isn't assigned to the collection, then `nil` is returned.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The name of the [custom template](/themes/architecture/templates#alternate-templates) assigned to the collection.",
      "name": "template_suffix"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "You can query for products from a certain vendor at the `/collections/vendors` URL\nwith a query parameter in the format of `?q=[vendor]`, where `[vendor]` is your desired product vendor.\n\n> Tip:\n> The query value is case-insensitive, so `apparelco` is equivalent to `ApparelCo` or `APPARELCO`.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The vendor name on a vendor collection page.",
      "name": "current_vendor"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "You can query for products of a certain type at the `/collections/types` URL\nwith a query parameter in the format of `?q=[type]`, where `[type]` is your desired product type.\n\n> Tip:\n> The query value is case-insensitive, so `shirts` is equivalent to `Shirts` or `SHIRTS`.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The product type on a product type collection page.",
      "name": "current_type"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The relative URL of the collection.",
      "name": "url"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "> Tip:\n> Use the [`date` filter](/docs/api/liquid/filters/date) to format the timestamp.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "A timestamp for when the collection was published.",
      "name": "published_at"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This image is added on the collection's page in the Shopify admin.",
      "examples": [],
      "return_type": [
        {
          "type": "image",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The image for the collection.",
      "name": "image"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [
        {
          "name": "Output the sort options",
          "description": "",
          "syntax": "",
          "path": "/collections/all",
          "raw_liquid": "{%- assign sort_by = collection.sort_by | default: collection.default_sort_by -%}\n\n<select>\n{%- for option in collection.sort_options %}\n  <option\n    value=\"{{ option.value }}\"\n    {%- if option.value == sort_by %}\n      selected=\"selected\"\n    {%- endif %}\n  >\n    {{ option.name }}\n  </option>\n{% endfor -%}\n</select>",
          "parameter": false,
          "display_type": "text",
          "show_data_tab": true
        }
      ],
      "return_type": [
        {
          "type": "array",
          "name": "",
          "description": "",
          "array_value": "sort_option"
        }
      ],
      "summary": "The available sorting options for the collection.",
      "name": "sort_options"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "If there's no `sort_by` URL parameter, then the value is `nil`.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The sort order applied to the collection by the `sort_by` URL parameter.",
      "name": "sort_by"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This is set on the collection's page in the Shopify admin.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "manual",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "best-selling",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "title-ascending",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "price-ascending",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "price-descending",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "created-ascending",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "created-descending",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The default sort order of the collection.",
      "name": "default_sort_by"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property can be used on the [product page](/themes/architecture/templates/product) to output `next` links.",
      "examples": [],
      "return_type": [
        {
          "type": "product",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The next product in the collection. Returns `nil` if there's no next product.",
      "name": "next_product"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property can be used on the [product page](/themes/architecture/templates/product) to output `previous` links.",
      "examples": [],
      "return_type": [
        {
          "type": "product",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The previous product in the collection. Returns `nil` if there's no previous product.",
      "name": "previous_product"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [],
      "return_type": [
        {
          "type": "number",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The total number of products in the current view of the collection.",
      "name": "products_count"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "> Tip:\n> Use the [paginate](/docs/api/liquid/tags/paginate) tag to choose how many products to show per page, up to a limit of 50.",
      "examples": [],
      "return_type": [
        {
          "type": "array",
          "name": "",
          "description": "",
          "array_value": "product"
        }
      ],
      "summary": "All of the products in the collection.",
      "name": "products"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This includes products that have been filtered out of the current view.\n\n> Tip:\n> To display the number of products in a filtered collection, use [`collection.products_count`](/docs/api/liquid/objects/collection#collection-products_count).",
      "examples": [],
      "return_type": [
        {
          "type": "number",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The total number of products in a collection.",
      "name": "all_products_count"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This includes tags for products that have been filtered out of the current view.\nA maximum of 1,000 tags can be returned.\n\n> Tip:\n> To display the tags that are currently applied, use [`collection.tags`](/docs/api/liquid/objects/collection#collection-tags).",
      "examples": [],
      "return_type": [
        {
          "type": "array",
          "name": "",
          "description": "",
          "array_value": "string"
        }
      ],
      "summary": "All of the tags applied to the products in the collection.",
      "name": "all_tags"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This doesn't include tags for products that have been filtered out of the current view.\nReturns `nil` if no tags have been applied, or all products with tags have been filtered out of the current view.",
      "examples": [],
      "return_type": [
        {
          "type": "array",
          "name": "",
          "description": "",
          "array_value": "string"
        }
      ],
      "summary": "The tags that are currently applied to the collection.",
      "name": "tags"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [
        {
          "name": "Create links to product types",
          "description": "Use the [`link_to_type`](/docs/api/liquid/filters/link_to_type) filter to create links to the product types in a collection.\n",
          "syntax": "",
          "path": "/collections/ingredients",
          "raw_liquid": "{% for product_type in collection.all_types -%}\n  {{- product_type | link_to_type }}\n{%- endfor %}",
          "parameter": false,
          "display_type": "text",
          "show_data_tab": true
        }
      ],
      "return_type": [
        {
          "type": "array",
          "name": "",
          "description": "",
          "array_value": "string"
        }
      ],
      "summary": "All of the product types in a collection.",
      "name": "all_types"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [
        {
          "name": "Create links to vendors",
          "description": "Use the [`link_to_vendor`](/docs/api/liquid/filters/link_to_vendor) filter to create links to the vendors in a collection.\n",
          "syntax": "",
          "path": "/collections/ingredients",
          "raw_liquid": "{% for product_vendor in collection.all_vendors %}\n  {{- product_vendor | link_to_vendor }}\n{% endfor %}",
          "parameter": false,
          "display_type": "text",
          "show_data_tab": true
        }
      ],
      "return_type": [
        {
          "type": "array",
          "name": "",
          "description": "",
          "array_value": "string"
        }
      ],
      "summary": "All of the product vendors in a collection.",
      "name": "all_vendors"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "Only filters relevant to the current collection are returned. Filters will be empty for collections that contain over 5000 products.\n\nTo learn about supporting filters in your theme, refer to [Support storefront filtering](/themes/navigation-search/filtering/storefront-filtering/support-storefront-filtering).",
      "examples": [],
      "return_type": [
        {
          "type": "array",
          "name": "",
          "description": "",
          "array_value": "filter"
        }
      ],
      "summary": "The [storefront filters](https://help.shopify.com/manual/online-store/themes/customizing-themes/storefront-filters) that\nhave been set up on the collection.",
      "name": "filters"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "The default is the [collection image](/docs/api/liquid/objects/collection#collection-image). If this image isn't available, then\nShopify falls back to the featured image of the first product in the collection. If the first product in the collection\ndoesn't have a featured image, then `nil` is returned.",
      "examples": [],
      "return_type": [
        {
          "type": "image",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The featured image for the collection.",
      "name": "featured_image"
    }
  ],
  "summary": "A [collection](https://help.shopify.com/manual/products/collections) in a store.",
  "name": "collection",
  "examples": [],
  "json_data": {
    "path": "/collections/ingredients/burning",
    "handle": "collection",
    "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