---
title: "collection"

doc_type: static
doc_category: static
doc_version: v20260901
source_url:
  html: 'https://developer.shopline.com/zh-hans-cn/docs/handlebars/objects/collection'
  md: 'https://developer.shopline.com/zh-hans-cn/docs/handlebars/objects/collection.md'
---


# collection

<div className="code-flex">
  <div>
    <ObjectSummary>店铺的商品分类</ObjectSummary>
    #### 属性
    <ObjectProperty name="all_products_count" types={["number"]}>
      <ObjectSummary>
        商品分类中的产品总数。

        这包括已从当前视图中过滤掉的产品。

        > **Tip**
>
> 要显示当前分类过滤后的产品数量，请使用 [collection.products_count](https://developer.shopline.com/zh-hans-cn/docs/handlebars/objects/collection.md#products_count).
      </ObjectSummary>
    </ObjectProperty>
    <ObjectProperty name="all_tags" types={["number"]}>
      <ObjectSummary>
        应用于商品分类中商品的所有标签。

        这包括已从当前视图中过滤掉的产品标签。最多可返回 1,000 个标签。
        > **Tip**
>
> 要显示当前应用的标签，请使用 [collection.tags](https://developer.shopline.com/zh-hans-cn/docs/handlebars/objects/collection.md#tags).
      </ObjectSummary>
    </ObjectProperty>
    <ObjectProperty name="all_types" types={["array of string"]}>
      <ObjectSummary>
        商品分类中的所有产品类型。
      </ObjectSummary>
    </ObjectProperty>
    <ObjectProperty name="all_vendors" types={["array of string"]}>
      <ObjectSummary>
        商品分类中的所有产品供应商。
      </ObjectSummary>
    </ObjectProperty>
    <ObjectProperty name="current_type" types={["string"]}>
      <ObjectSummary>
        当前商品分类页的产品类型

        您可以在 `/collections/types` URL添加 `?q=[type]` 参数查询特定类型的产品，其中 `[type]` 是您想要的产品类型。
        > **Tip**
>
> 参数值大小写不敏感，因此 `shirts` 等同于 `Shirts` 或 `SHIRTS`。
      </ObjectSummary>
    </ObjectProperty>
    <ObjectProperty name="current_vendor" types={["string"]}>
      <ObjectSummary>
        当前商品分类页的供应商。

        您可以在 `/collections/vendors` URL添加 `?q=[vendor]` 参数查询特定类型的产品，其中 `[vendor]` 是您想要的产品供应商。

        > **Tip**
>
> 参数值大小写不敏感，因此 `apparelco` 等同于 `ApparelCo` 或 `APPARELCO`。
      </ObjectSummary>
    </ObjectProperty>
    <ObjectProperty name="default_sort_by" types={["string from a set of values"]}>
      <ObjectSummary>
        商品分类的默认排序顺序。

        这是在 Shopline 后台的商品分类页面上设置的。
      </ObjectSummary>
    </ObjectProperty>
    <ObjectProperty name="description" types={["string"]}>
      <ObjectSummary>
        商品分类的描述
      </ObjectSummary>
    </ObjectProperty>
    <ObjectProperty name="featured_image" types={[<Mdx>[image](https://developer.shopline.com/zh-hans-cn/docs/handlebars/objects/image.md)</Mdx>]}>
      <ObjectSummary>
        商品分类的特色图片。

        默认为分类封面图。如果此图片不可用，则 Shopline 会回退到分类中第一个产品的特色图片。如果集合中的第一个产品没有特色图片，则返回`null`。
      </ObjectSummary>
    </ObjectProperty>

    {/* TODO filter 待@俊延补充 */}
    <ObjectProperty name="filters" types={[<Mdx>array of [filter](https://developer.shopline.com/zh-hans-cn/docs/handlebars/objects/filter.md)</Mdx>]}>
      <ObjectSummary>
       The storefront filters that have been set up on the collection.

       Only filters relevant to the current collection are returned. Filters will be empty for collections that contain over 1000 products.
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="handle" types={["string"]}>
      <ObjectSummary>
        商品分类的[handle](https://developer.shopline.com/zh-hans-cn/docs/handlebars/objects/handle.md)。
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="id" types={["string"]}>
      <ObjectSummary>
        商品分类的ID。
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="image" types={[<Mdx>[image](https://developer.shopline.com/zh-hans-cn/docs/handlebars/objects/image.md)</Mdx>]}>
      <ObjectSummary>
        商品分类的封面图片。

        这是在 Shopline 后台的商品分类页面上设置的。
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="products" types={[<Mdx>array of [product](https://developer.shopline.com/zh-hans-cn/docs/handlebars/objects/product.md)</Mdx>]}>
      <ObjectSummary>
        商品分类中的所有产品。
        > **Tip**
>
> 使用 [paginate](https://developer.shopline.com/zh-hans-cn/docs/handlebars/helpers/iteration/paginate.md) helper 帮助每页显示多少产品, 最多50个。
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="products_count" types={["number"]}>
      <ObjectSummary>
        当前商品分类视图中的产品总数。
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="published_at" types={["string"]}>
      <ObjectSummary>
        商品分类发布时间。
        > **Tip**
>
> 使用 [`date helper`](https://developer.shopline.com/zh-hans-cn/docs/handlebars/helpers/format/date.md) 格式化时间。
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="sort_by" types={["string"]}>
      <ObjectSummary>
        通过 `sort_by` URL 参数应用于商品分类的排序顺序。

        如果没有 `sort_by` URL 参数，则值为 `null`
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="sort_options" types={[<Mdx>array of [sort_option](https://developer.shopline.com/zh-hans-cn/docs/handlebars/objects/sort-option.md)</Mdx>]}>
      <ObjectSummary>
        商品分类可用排序选项。
        <Example data={['collection.sort_options', 'collection.sort_by', 'collection.default_sort_by']} layout="vertical">

          ```handlebars

          {{ assign 'sort_by' (default collection.sort_by collection.default_sort_by) }}

          <select>
          {{#each collection.sort_options as |option| }}
            <option
              value="{{ option.value }}"
              {{#if option.value '==' sort_by }}
                selected="selected"
              {{/if}}
            >
              {{ option.name }}
            </option>
          {{/each}}
          </select>

          ```
        </Example>
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="tags" types={["array of string"]}>
      <ObjectSummary>
        当前应用于商品分类的标签。

        这不包括已从当前视图中过滤掉的产品标签。如果没有应用任何标签，或者所有带有标签的产品都已从当前视图中过滤掉，则返回 `empty array`。
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="title" types={["string"]}>
      <ObjectSummary>
        商品分类的标题。
      </ObjectSummary>
    </ObjectProperty>

    <ObjectProperty name="url" types={["string"]}>
      <ObjectSummary>
        商品分类的相对URL。
      </ObjectSummary>
    </ObjectProperty>
  </div>

  <div>
    <ObjectAccess
      object="collection"
      global={false}
      templates={[
        { name: 'collection' },
      ]}
    />
  </div>
</div>
