Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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
Hi, I have tried the following approach, but it doesn't work. I wonder how I can get the size of the metafields list.
{% if product.metafields.products.related.value.size > 0 %}
<p>Some related products here.</p>
{% else %}
<p>It is empty.</p>
{% endif %}
Where {% product.metafields.products.related.type %} is list.product_reference.
Solved! Go to the solution
This is an accepted solution.
Hi @henglw0621,
Sorry for the confusion, you can use the following code:
{% if product.metafields.products.related.value != blank %}
<p>Some related products here.</p>
{% else %}
<p>It is empty.</p>
{% endif %}
Hope it helps!
Hi @henglw0621
Can you let us know where you want to display the metafields and the theme which you are using?
Hi @Tinytasks, thank you for reply.
I am using the following theme and display the metafields on the product page.
Hi @henglw0621,
You can refer: https://shopify.dev/api/liquid/objects#paginate
Hope it helps!
Hi @LitExtension, thank you for reply.
I have checked the pagination reference you provided, but I don't know how I can apply it to my code. I would appreciate if you could give me some example code on how to apply pagination with the metafield list.
This is an accepted solution.
Hi @henglw0621,
Sorry for the confusion, you can use the following code:
{% if product.metafields.products.related.value != blank %}
<p>Some related products here.</p>
{% else %}
<p>It is empty.</p>
{% endif %}
Hope it helps!
Although this has been solved, here is a simpler solution:
Size of Metafield list = {{ product.metafields.products.related.value | size }}
{% liquid
assign related_products = product.metafields.products.related | split: ','
echo related_products | size
%}