# 同ページ内で複数のコレクションを表示する場合の実装方法

**URL:** <https://community.shopify.com/t/topic/19753>\
**Category:** 技術的なQ＆A\
**Created:** [September 3, 2020, 9:02pm UTC](https://community.shopify.com/t/topic/19753 "2020-09-03T21:02:04Z")\
**Posts on this page:** 4\
**Page:** 1

## AI-generated summary

Shopifyテーマで、同一ページ内に「NEW」「MENS」など複数コレクションを表示する実装方法が焦点。質問者は1つのsection内に複数blockのschemaを定義し、連続表示しようとしたが、テーマエディタ上では設定できても実際の表示でエラーになった。theme watch上では明確なエラーは出ていない。

議論では、参考記事のように新しいsectionやsnippetを使う方法がある一方、目的が単に複数コレクションの表示であれば、sectionを無理に使わず、対象ページのLiquidにcollection object（Shopifyのコレクション情報を扱うオブジェクト）を直接出力する方法が提案された。あわせて、sectionsやblocksの基本構造を解説した公式ブログも案内されている。

その後、質問者は暫定対応として、ホームとは別のページに2つのsectionを読み込み、それぞれにschemaを配置する形で2つのコレクション表示を実現した。根本的な実装理解は今後の学習課題として残るが、当面の表示方法は確保できた状態。

<div class="post-metadata">

**Author:** ![hakuto](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/hakuto/32/36914_2.png) [@hakuto](https://community.shopify.com/u/hakuto)\
**Post date:** [September 3, 2020, 9:02pm UTC](https://community.shopify.com/t/topic/19753/1 "2020-09-03T21:02:04Z")

</div>

いつもお世話になります。

理解が浅い為、ご指摘をお願い致します。

例えば ホームページ上で「NEWコレクション」「MENSコレクション」など複数のコレクションを混在させて商品を表示させたい場合 下記のような設定を用意して複数のschemaを連続して表示させようとしました。

```ruby
{% schema %}
{
"blocks":[

{
"type": "first-section",
"name": "Homepage Products1",
"settings": [

{
	"type": "text",
	"id": "title",
	"label": "Heading",
	"default":"Trending Products"
	},
{
"type": "collection",
"id": "collection",
"label": "Collection"
},
{
"type": "range",
"id": "product_limit",
"label": "Product Limit",
"min": 3,
"max": 10,
"default": 6
}
]
},

{
"type": "second-section",
"name": "Homepage Products2",
"settings": [
{
	"type": "text",
	"id": "title",
	"label": "Heading",
	"default":"Mens Products"
	},

{
"type": "collection",
"id": "collection",
"label": "Collection"
},
{
"type": "range",
"id": "product_limit",
"label": "Product Limit",
"min": 3,
"max": 10,
"default": 6
}
]
}
]
}
{% endschema %}

```

```markup

	

	
	

```

カスタマイズ画面は上手く実装されたようなのですが、表示がエラーとなってしまいます。（theme watchでのエラーは無し）

 ![管理画面](https://canada1.discourse-cdn.com/shopifyforum/original/3X/e/0/e01566e5738bac6230caf0e809df8687818ed13b.png)

参考サイト上の説明では新たに セクションmuluti\_section.liquid や スニペットを作成するように説明されていますが理解できません。

セクション内でのループの作成方法など、多々問題があると思いますが どうか御指南宜しくお願い致します。

参考サイト [http://www.codeshopify.com/blog\_posts/shopify-sections-with-dynamic-blocks](http://www.codeshopify.com/blog_posts/shopify-sections-with-dynamic-blocks)

---

<div class="post-metadata">

**Author:** ![hakuto](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/hakuto/32/36914_2.png) [@hakuto](https://community.shopify.com/u/hakuto)\
**Post date:** [September 4, 2020, 4:27pm UTC](https://community.shopify.com/t/topic/19753/2 "2020-09-04T16:27:22Z")

</div>

管理画面でホームページとは別に作ったページ上で2つのセクションを読み込み、その2つのセクションそれぞれにschemaを配置する事で、とりあえず1ページ上で2つのコレクションを実装してみました。

 ![370B1241-5673-490A-91D7-A65D39B7B254.jpeg](https://canada1.discourse-cdn.com/shopifyforum/original/3X/4/e/4e483aa88badd8db411cc251d93f362894a533d0.jpeg)

---

<div class="post-metadata">

**Author:** ![junichiokamura](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/junichiokamura/32/299737_2.png) [@junichiokamura](https://community.shopify.com/u/junichiokamura)\
**Post date:** [September 16, 2020, 12:18pm UTC](https://community.shopify.com/t/topic/19753/3 "2020-09-16T12:18:09Z")

</div>

セクションの概要については以下のブログにまとめていますので、ご参照ください。  
[https://www.shopify.jp/blog/partner-shopify-theme-section-first-create](https://www.shopify.jp/blog/partner-shopify-theme-section-first-create)

単純にコレクションを全て表示したいだけの場合は、セクションを無理に使う必要はないと思います。

以下のドキュメントを参考にして、表示させたいページのliquidに、collection objectを表示させれば良いと思います。

[https://shopify.dev/docs/themes/liquid/reference/objects/collection](https://shopify.dev/docs/themes/liquid/reference/objects/collection)

---

<div class="post-metadata">

**Author:** ![hakuto](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/hakuto/32/36914_2.png) [@hakuto](https://community.shopify.com/u/hakuto)\
**Post date:** [September 16, 2020, 2:09pm UTC](https://community.shopify.com/t/topic/19753/4 "2020-09-16T14:09:03Z")

</div>

岡村さん、ありがとうございます！

ブロックの部分もブログに詳しく書いてありますね、勉強不足でした。

コレクションオブジェクトに関しても参考にさせていただきます！
