{% assign ladies_collection = collections | where: "handle", "ladies" | first %}
{% assign tops_collection = collections | where: "title", "トップス" | first %}
<div>{{ ladies_collection.title }}</div>
<div>{{ tops_collection.title }}</div>
レディース
トップス
・collectionsオブジェクト: そのショップの全てのcollectionオブジェクトを要素として持っている配列。
・whereフィルター: 条件を指定してその条件に該当する特定のオブジェクトを抜き出し、配列として返す
・firstフィルター: 配列の最初の要素を取り出す
firstフィルターをかけるか[0]でインデックスを指定しないと、配列のままなので注意(上の場合、何も表示されない)。
参考
collectionsオブジェクト
https://shopify.dev/docs/themes/liquid/reference/objects#collections
whereフィルター
https://shopify.github.io/liquid/filters/where/
firstフィルター
https://shopify.github.io/liquid/filters/first/
追記(2020/11/30)
これでもいけました。こちらの方が簡単です。
{% comment %}collections[{コレクションのhandle}]{% endcomment %}
{% assign ladies_collection = collections['ladies_collection'] %}
{% comment %}collections.{{コレクションのhandle}}{% endcomment %}
{% assign tops_collection = collections.tops %}
<div>{{ ladies_collection.title }}</div>
<div>{{ tops_collection.title }}</div>
レディース
トップス
なんでcollections
オブジェクトのインデックスにコレクションのhandle
入れると、オブジェクトが取り出せるんだろう。
どこかにドキュメントないかな。。。
→これかな。
Accessing handle attributes
In many cases you may know the handle of a object whose attributes you want to access. You can access its attributes by pluralizing the name of the object, then using either the square bracket ( [ ] ) or dot ( . ) notation.
https://shopify.dev/docs/themes/liquid/reference/basics/handle
collectionsオブジェクトって、collectionオブジェクトを含んでいるわけで、おそらくArrayとは、やっぱりちょっと違うんだなぁ(オブジェクトの配列を作るのって、できなかったはず)
collectionsとかpagesとか、Global objectsだけ特殊(Arrayだけどhandleを使ってハッシュやオブジェクトのようにアクセスできる)なのかな?
→あ、Global Objects
なんだから、オブジェクトなのか(handleがkey)。。。
参考:
You have the collection handle. collections is a global Liquid object. Therefore you can reference any specific collection using the handle.
Shopifyのcollectionに関するオブジェクト