Display collection based on metatag

Hi,

I found this code example in the liquid reference

{% for collection in collections %}
  {{- collection.title | link_to: collection.url }}
{% endfor %}

What I did was make a collection metafield called “parentcollection”. What I want to do is display a table of child collections based on the parent collection. For instance, if you have a parent collection called “Boys”, the children accounts Boys Pants, Boys Shirts, Boys Shoes, etc, would have “boys” in the parent collection.

But instead of displaying in a grid, I want them to display as rows
Child Collection1 linkChild Collection1 Image*/Child Collection1 link* | Child Collection1 Metafield 1 | Child Collection1 metafield 2 | etc.
Child Collection2 linkChild Collection2 Image*/Child Collection2 link* | Child Collection2 Metafield 1 | Child Collection2 metafield 2 | etc.
etc

The metafield would be selected based on a match of the ParentCollection for instance “boys.fabric”, “boys.season”, etc.

This could vary based on the metafields, so Girls could have “girls.patterns” first, then “girls.topstyle”, etc.

Any suggestions on how to iterate a list like this?

Thanks

Pete

Insert the following code into your collection template to display the child collections in a table format

{% assign parent_collection = 'boys' %} 

  
  {% for collection in collections %}
    {% if collection.metafields.parentcollection == parent_collection %}
      
    {% endif %}
  {% endfor %}

| Collection | Image | Fabric | Season |
| - | - | - | - |
| <br>          <br>            {{ collection.title }}<br>          <br>         | <br>          <br>            <br>          <br>         | <br>          {{ collection.metafields.boys.fabric }} <br>         | <br>          {{ collection.metafields.boys.season }} <br>         |

This code sets up a table and iterates over the collections. It checks if the “parentcollection” metafield matches the desired parent collection (e.g., “boys”). If it matches, it displays the collection title, image, and other metafields in a table row.

Replace boys with the handle of your parent collection and adjust the metafield keys (boys.fabric, boys.season, etc.) to match your setup.

Thanks. I was thinking of something along those lines. This was just what I was looking for. I am surprised that no template has a tabular layout for collections.