Happening now! Shopify Community AMA: PayPal Express Migration to Shopify Payments | Ask your questions to be answered by our team.

Why isn't my metafield displaying correctly on my product detail page?

Solved

Why isn't my metafield displaying correctly on my product detail page?

gillesraw
New Member
4 0 0

Hi dear community !

 

I have an issue on the display of a metafield on my product detail page

 

I've created a new custom data :

gillesraw_0-1709284865338.png

 

I added it in a personnalized liquid section of my page 

 

gillesraw_1-1709284928886.png

My problem is that it doesnt display the link to the collection I add to my product but it displays that :

gillesraw_2-1709284986986.png

 

I'm using the Dawn theme and the website is not opened at the moment

 

thanks for your help 🙂 

 

Accepted Solution (1)
devmont-digital
Shopify Partner
143 32 38

This is an accepted solution.

Here is the updated code:

 

{% for collection in product.metafields.custom.collectionsmulti.value %}
<a href="{{ collection.url }}">{{ collection.title }}</a><br>
{% endfor %}

 

 



Found our answer helpful? If so, Don't forget to show your support by liking and accepting the solution.
Looking for more help and expert consultation? Feel free to contact us at Shopify Expert or visit our website www.devmontdigital.io
Hire us for your project by simply emailing us at [email protected]

View solution in original post

Replies 6 (6)

devmont-digital
Shopify Partner
143 32 38

Hi @gillesraw,

If you want to print your collection link here is the code above:

 

{% assign collection_handle = product.metafields.custom.collections.value.handle %}
{% assign collection = collections[collection_handle] %}

{% if collection %}
  <a href="{{ collection.url }}">{{ collection.title }}</a>
{% endif %}
Found our answer helpful? If so, Don't forget to show your support by liking and accepting the solution.
Looking for more help and expert consultation? Feel free to contact us at Shopify Expert or visit our website www.devmontdigital.io
Hire us for your project by simply emailing us at [email protected]
gillesraw
New Member
4 0 0

Hi ! thanks for your answer ! I made a mistake, I want to display a list of collections and not a single collection, so I created a new metafield named product.metafields.custom.collectionsmulti

 

I tried this but it doesnt work: 

{% for collection_metafield in product.metafields.custom.collectionsmulti %}
{% assign collection_handle = collection_metafield.handle %}
{% assign collection = collections[collection_handle] %}
{% if collection %}
<a href="{{ collection.url }}">{{ collection.title }}</a><br>
{% endif %}
{% endfor %}

devmont-digital
Shopify Partner
143 32 38

You're welcome! If you want to list collections, you don't necessarily have to create a metafield. Just use the provided code.

 

 <div id="all_collection">
  {% for collection in collections %}
  <div class="single_collection_name"><span class="custom-design"><a href="{{ collection.url }}">{{ collection.title }}</a></span></div>     
  {% endfor %} 
</div>

 

Found our answer helpful? If so, Don't forget to show your support by liking and accepting the solution.
Looking for more help and expert consultation? Feel free to contact us at Shopify Expert or visit our website www.devmontdigital.io
Hire us for your project by simply emailing us at [email protected]
gillesraw
New Member
4 0 0

I have a metafield multivalued to display some categories linked to my product :

gillesraw_0-1709550027821.png

 

definition :

gillesraw_1-1709550059019.png

 

 

thanks again for your time 🙂

devmont-digital
Shopify Partner
143 32 38

This is an accepted solution.

Here is the updated code:

 

{% for collection in product.metafields.custom.collectionsmulti.value %}
<a href="{{ collection.url }}">{{ collection.title }}</a><br>
{% endfor %}

 

 



Found our answer helpful? If so, Don't forget to show your support by liking and accepting the solution.
Looking for more help and expert consultation? Feel free to contact us at Shopify Expert or visit our website www.devmontdigital.io
Hire us for your project by simply emailing us at [email protected]
gillesraw
New Member
4 0 0

thanks ! you're the best !!