We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Loop through metaobject entries

Solved

Loop through metaobject entries

aodev
Shopify Partner
2 1 0

In my store I have a brand metaobject whose entries have a name and image. I would like to list all the brands in the store in my theme, but I can't get the list of entries.

 

Here's what I tried based on the documentation of these objects and chatGPT help:

{% assign brands = shop.metaobjects.custom.brand %}
{% assign mobjects = shop.metaobjects %}

<pre>{{ mobjects | json }}</pre>
<pre>{{ brands | json }}</pre>

<ul class="dropdown-list">
  {% for brand in brands %}
    <li class="dropdown-item">
      <a class="dropdown-link" href="/pages/brand?name={{ brand | handleize }}">{{ brand.name.value }}</a>
    </li>
  {% endfor %}
</ul>

 

`mobjects` in the <pre> element returns {"error":"json not allowed for this object"}, and `brands` returns null - that's why no items appear in my list.

Thank you in advance for your help and I apologize if my problem is due to an omission in the documentation.

Accepted Solution (1)

aodev
Shopify Partner
2 1 0

This is an accepted solution.

Sorry for the confusion, as I thought I missed some of the documentation: Metaobject definition (Loop over entries of a metaobject definition) 

View solution in original post

Reply 1 (1)

aodev
Shopify Partner
2 1 0

This is an accepted solution.

Sorry for the confusion, as I thought I missed some of the documentation: Metaobject definition (Loop over entries of a metaobject definition)