Struggling to display only the metaobject attached to a metafield in liquid

Struggling to display only the metaobject attached to a metafield in liquid

crumbscrumbs
Visitor
3 0 0

I have a metaobject called "discography" with a number of metafields giving information about releases, one metafield discography.variants references another metaobject called variants which includes information about various pressings.

 

I have a discography page which displays packshots for all of my releases using this code [I've removed my website name just for privacy 🙂

 

 

<div class="discography-grid">

  {% for discography_item in shop.metaobjects.discography.values %}
  
      <a class="discography-item" href="https://store.website.com{{ discography_item.system.url }}">
 
      {% if discography_item.packshot %}
      
          <img src="{{ discography_item.packshot | image_url }}" alt="{{ discography_item.title }}" class="discography-packshot">
    
      {% endif %}
      <h3 class="discography-title">
       {{ discography_item.title }}
      </h3>
      <p class="discography-catalog-number">
        Catalog #: {{ discography_item.catalog_number }}
      </p>
        </a>
  {% endfor %}

</div>

 

 

But on the individual pages I can't figure out how to display the variants metafield / metaobject?

This prints information for EVERY variant entry not just the entries that are attached to the discography.variants metafield?

 

<div class="discography-variants">
  <h3>Variants:</h3>
  <ul>
    {% for variant in shop.metaobjects.variants.values %}
    
        <li>
          <strong>{{ variant.pressing_info }}</strong>
        </li>
     
    {% endfor %}
  </ul>
</div>

Sorry if any of that isn't described well.

Please help!

 

Screenshot 2024-12-08 at 1.42.02 PM.png

Screenshot 2024-12-08 at 1.44.16 PM.png

 

Screenshot 2024-12-08 at 1.49.01 PM.png

Replies 3 (3)

namphan
Shopify Partner
2695 349 397

Hi @crumbscrumbs,

Please change code:

shop.metaobjects.variants.values => variant.metaobjects.variants.values

 

Coffee tips fuels my dedication.
Shopify Development Service
PageFly Page Builder Optimize your Shopify store (Free plan available)
Need help with your store? namphan992@gmail.com
crumbscrumbs
Visitor
3 0 0

Unfortunately with that change nothing displays?

<pre>All Variants: {{ variant.metaobjects.variants.values | json }}</pre> returns null.

 

<div class="discography-variants">
<h3>Variants:</h3>
<ul>
{% for variant in variant.metaobjects.variants.values %}

<li>
<strong>{{ variant.pressing_info }}</strong>
</li>

{% endfor %}
</ul>
</div>

namphan
Shopify Partner
2695 349 397

Hi @crumbscrumbs,

The variant declared? If not, please change the code below:

{% for variant_product in product.variants %}
<pre>All Variants: {{ variant_product.metaobjects.variants.values | json }}</pre> returns null.

<div class="discography-variants">
<h3>Variants:</h3>
<ul>
{% for variant in variant_product.metaobjects.variants.values %}

<li>
<strong>{{ variant.pressing_info }}</strong>
</li>

{% endfor %}
</ul>
</div>
{% endfor %}
Coffee tips fuels my dedication.
Shopify Development Service
PageFly Page Builder Optimize your Shopify store (Free plan available)
Need help with your store? namphan992@gmail.com